Saturday 15 March 2014

c# - how to bind a datagrid with a class contains object of another class -


sry But I'm new with wpf, I have a generated message and trying to bind it to a datagrid I am / P>

  class generated message {public CanMessage cmsg {set; get; } Public int cycle time set {set; get; } Public generated message () {}} Public category canmes {public byte [data] {set; get; } Public Use DLC {Set; get; } Public user flags {set; get; } Public UIT ID {Set; get; } Public Unlock Res1 {Set; get; } Public Umbrella Res2 {Set; get; }}   

As the user mamassas class is an object of the canmease class, I have done it with the Canmessage class as below

  Add to the item traceable / * - A datagrid - * / (new canmase) {data = msg.data, dlc = msg.dlc, id = msg.id, flags = msg.flags, res1 = msg.res1, res2 = Msg .res2}); // xml file below & lt; DataGrid x: name = "tracetable" grid. Column = "0" docpaigne.doc = "top" selectionmode = "extended" automatically generated column = "wrong" selection unit = "full-rouge" margin = "0, 45, 4,0" & gt; & Lt; DataGrid.Columns & gt; & Lt; DataGridTextColumn binding = "{binding path = data}" header = "data" isReadOnly = "true" /> & Lt; DataGridTextColumnBinding = "{Binding Path = DLC}" Header = "DLC" IsReadOnly = "true" /> & Lt; DataGridTextColumnBinding = "{Binding Path = ID}" Header = "ID" isReadOnly = "true" /> & Lt; DataGridTextColumnBinding = "{Binding Path = Flag}" Header = "Flag" IsReadOnly = "true" /> & Lt; DataGridTextColumn binding = "{binding path = res1}" header = "res1" isReadOnly = "true" /> & Lt; DataGridTextColumn binding = "{binding path = res2}" header = "res2" isReadOnly = "true" /> & Lt; /DataGrid.Columns> & Lt; / Data grid & gt;   

So my question is how to make it a message class generated. I want to see all the data messaging datagrid + cycle time (datagrid with 7 columns)

If I understand the question correctly, then you should add items of type "Generated Message" and should force it like this:

  binding = {binding cycle time } Binding = {binding cmsg.dlc} ... etc.   



Generally you should not manually add items to the datagrid. The best way to do this: Create Observable Collection in a View Module in the DataGrid and set the "Items Sauce" in the DataGrid:

  ITEMSource = "{Binding Collection}"   

Then add items to this collection, and not on the DataGrid. To better understand that subject you can read about MVVM pattern; -).

No comments:

Post a Comment