0

I mean how should I display my datastructure for I can work with it like with table? I want to have a table with rows and columns can be dynamicaly added and removed, but in the rest is should looks like a table.

Now it's represented like IList>, because I should resize it, as I said before. But now i want to display it in DataGrid, and be able to have rows, coulmns, and work with "Cells". But i cannot bind it properly, it it does not display anything, only an empty cell for every row.

What should I do? Or mby use arrays and resize them after each row/column addition?

Please, advice.

Now I have this one:

    private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
    {
        var storage = new Storage();
        storage.Data.Add(new DataRow("Bla-bla")
                     {
                         new DataEntity() {Text = "bla-bla", Forces = new[] {ForceEnum.AA}},
                         new DataEntity() {Text = "bla-bla", Forces = new[] {ForceEnum.UA}}
                     });
        DataListView.DataContext = new StorageModel(storage);
    }

public class StorageModel
{
    public StorageModel()
    {

    }

    public StorageModel(IStorage storage)
    {
        DataRowList = new ObservableCollection<DataRow>(storage.Data);
    }

    public ObservableCollection<DataRow> DataRowList
    {
        get;
        set;
    }
}
public class DataRow : IList<DataEntity>
{
    public string Name { get; private set; }
    private readonly List<DataEntity> _list = new List<DataEntity>();
...

_

    <ListView ItemsSource="{Binding DataRowList}" Name="DataListView">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ListView ItemsSource="{Binding}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" />
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

i want be able to create something similar to this, but with 2-way binding...

Community
  • 1
  • 1
Alex Zhukovskiy
  • 9,565
  • 11
  • 75
  • 151

1 Answers1

1

You seem to be asking for TreeView and not ListView since you have a tree alike data structure.

If you do not want to use a TreeView I would suggest you to use a simple ListView with a small trick. That is you could explose an Expander which will add or remove items underneath parent with an indent to fake tree look and still all cells in column would be resized together.

Btw dont forgot to define columns

Here is how:

<ListView Margin="10" Name="lvUsers">
        <ListView.View>
                <GridView>
                        <GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Name}" />
                        <GridViewColumn Header="Age" Width="50" DisplayMemberBinding="{Binding Age}" />
                        <GridViewColumn Header="Mail" Width="150" DisplayMemberBinding="{Binding Mail}" />
                </GridView>
        </ListView.View>
</ListView>

If you wish to implement that expander trick behavior I would suggest you to listen to event OnExpanded and add or remove the needed rows.

dev hedgehog
  • 8,698
  • 3
  • 28
  • 55