I want to bind CLR property into datagrid Row How to Bind row binding in datagrid(Twoway Mode)
CodeBehind:
public partial class TechnicalPropertiesU_Var : Window
{
public TechnicalPropertiesU_Var()
{
InitializeComponent();
List<Myclass> myclassList = new List<Myclass>();
myclassList.Add(new Myclass() { IA = 0, IB = 0, IC = 0, ID = 0, IE = 0, IF = 0, IF = 0 });
MyGrid.ItemsSource = myclassList;
}
}
MyWindow Xaml:
<Grid>
<DataGrid x:Name="MyGrid" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Argument Name"></DataGridTextColumn>
<DataGridTextColumn Header="Argument Value"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
Model Class
public class Myclass
{
private int iA;
private int iB;
private int iC;
private int iD;
private int iE;
private int iF;
private int iG;
public int IA{get=>iA; set=>iA =value;}
public int IB{get=>iB; set=> iB =value;}
public int IC{get=>iC; set=> iC =value;}
public int ID{get=>iD; set=> iD =value;}
public int IE{get=>iE; set=> iE =value;}
public int IF{get=>iF; set=> iF =value;}
public int IG{get=>iG; set=> iG =value;}
}
How to get particular column in datagrid field. please give any samples

If the result you are trying to get is a table with two columns (see your image) then you obviously mixed up rows and columns I guess. You data class must have two properties:
ArgumentNameandArgumentValue. You must know that each item (or each instance ofMyClass) will be displayed as a row. Now, for each row create an instance of ofMyClassand add it to the source collection. The bind theDataGridTextColumn.Bindingproperty to the column's related property of theMyClassmodel.The following example will show the table from your image:
MyTableClass.cs
TechnicalPropertiesU_Var.xaml.cs
MyWindow.xaml
To address your comment: "i dont want to bind argumentname and argument value property. i want to bind my own CLR property. because i have 250 variables."
I don't have to understand your intentions to tell you that this is a bad idea. A class shouldn't have 250 properties. Your image shows clearly that not all 250 properties have a relation, but only two have.
In your case a datum consists of a string value e.g.,
"IA"and a numeric value e.g.5. You should change your class to reflect this.You should know that in common relational database design a data record is represented by a row. Each row is an object and each column of this row an attribute of this object. The
DataGrid´ is designed with the same intention: each row is an item of theDataGrid.ItemsSource`. Each item is a separate instance. It is common to read any table e.g., a price table of products, from left to right, where each column of a row is expected to relate to a single data item e.g. product.I highly recommend to drop your initial intention and change your data classes to reflect the relationship of your data like the example's
MyTableClassreflects the relation of a data object (row) with two attributes (columns).