I am given a table-like datasource in Dictionary<string, IList>
, and would like to show its content in MultiColumnListView
. The Doc indicates that I need to organize data in a IList
of Object which have multiple properties for each column. But our datasource of Dictionary<string, IList>
is designed for dynamic adding columns. I tried to use bindingPath
, but MultiColumnListView
shows nothing. Here is a gist of my code:
Dictionary<string IList> CondTest; // given from another object
MultiColumnListView condtestcontent; // the visual-element in our UIDocument
condtestcontent.dataSource = CondTest;
foreach (var c in CondTest.Keys)
{
var col = new Column
{
name = c,
title = c,
width = 100,
bindingPath = $"[{c}]",
makeCell = () => new Label(),
bindCell = (VisualElement v, int i) => (v as Label).text = CondTest[c][i].ToString())
};
condtestcontent.columns.Add(col);
}
I don’t know if the approch here is ever going to work, or i have to reorganize data into something like List<KeyValuePair>
?
Any suggestions is much appreciated, Thanks.
Indeed, we only support a flat IList
for the itemsSource
and don’t plan on supporting dictionaries any time soon. It would be possible to have a somewhat dictionary-like IList
implementation of your own, where you override methods to point to your dictionary data source, and manage column assignation and data access manually, but it might be more trouble in the end.
@griendeau_unity Thanks for the clarification. The reason of using a Dictionary
is that the columns are not constant. Some times only 2 columns of e.g. LIst<int>
and List<string>
, but other times more than 3 columns with different types for each column. The current IList
approach assumes each row have the same column properties.
The other way i am wandering is to use additem/deleteitem
, e.g. i can iterate each row of my Dictionary, and programmably add the row of the MultiColumnListView
. and if column being added/removed. i redo the process and rebuilt items. would this approach possible?
The list view API doesn’t prevent using different in each column, the bindCell is up to you. The source could have a List but fill it with inherited instances from that BaseType, with different attribute types per item. As long as the bindCell allows the different supported types, it should be handled gracefully.
ex:
class BaseType { }
class TypeWithStrings : BaseType { string title; string name; }
class TypeWithAMix : BaseType { int index; string name; }
class FlexibleType : BaseType { List<object> anyTypePerColumn; }