I’m relatively new to WPF and I couldn’t find anything solving my current issue so I’m trying here.
I have a class called ToolType which has a couple of parameters(name, id, model) and it also has a List of Tools(ID, RFID, shelfID).
In one of my views I need to show
| ID | RFID | Name | Model | ShelfID |
as columns in a DataGrid, so a mixture of “parent” and “child” classes, but I just can’t figure out how to go about doing that – besides making a completely new string array containing the information.
Does anyone have any idea how to it?
Code:
class Tool
{
public string ID { get; set; }
public string RFID { get; set; }
public string space { get; set; }
...
}
class ToolType
{
public string ID { get; set; }
public string name { get; set; }
public string model { get; set; }
public int interval { get; set; }
public List<Tool> toolsList = new List<Tool>();
...
}
WPF for the DataGrid:
<DataGrid AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" ItemsSource="{Binding}" Margin="40,43,0,0" Name="dataGrid4" VerticalAlignment="Top" Width="305">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ID}" Header="ID" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding RFID}" Header="RFID" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding name}" Header="Type" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding model}" Header="Model" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding nextMaintenance}" Header="Dato" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding space}" Header="Plads" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>
what about grouping your Tools by ToolType: How to: Group, Sort, and Filter Data in the DataGrid Control