Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wpf

datagrid

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);
like image 732
Edward Tanguay Avatar asked May 27 '09 15:05

Edward Tanguay


1 Answers

Untested, but the following should work:

dgtc.Binding = new Binding("FirstName");
like image 117
samjudson Avatar answered Sep 29 '22 22:09

samjudson