Thursday, April 21, 2011

How can I set the binding of a DataGridTextColumn in code?

I'm using the toolkit:DataGrid from CodePlex.

I'm generating the columns in code.

How can I set the equivalent of {Binding FirstName} in code?

Or alternatively, how can I just set the value, that's all I need to do, not necessarily bind it. I just want the value from my model property in the cell in the datagrid.

DataGridTextColumn dgtc = new DataGridTextColumn();
dgtc.Header = smartFormField.Label;
dgtc.Binding = BindingBase.Path = "FirstName"; //PSEUDO-CODE
dgtc.CellValue= "Jim"; //PSEUDO-CODE
CodePlexDataGrid.Columns.Add(dgtc);
From stackoverflow
  • Untested, but the following should work:

    dgtc.Binding = new Binding("FirstName");
    

0 comments:

Post a Comment