The DataGrid bindings are good, but sometimes we need to dynamically control rows or columns based on the model content.
At this point, we need to use the row Load event: When each row of data is loaded, the corresponding table display is controlled based on the contents of the data.
For example, we want to have a red color for every five lines, so you can:
SolidColorBrush r = new SolidColorBrush ( colors.red); private void datagrid1_ Loadingrow (object sender, DataGridRowEventArgs e) {CData c = e.row.datacontext as
CData;
if (c.id%
5 =
0
) e.row.background =
R;
else
E.row.background =
new
SolidColorBrush (colors.white); }
If you want to change the style or content of a custom column in a row based on the value of the model, you can do the following:
Private voidDg_source2_loadingrow (Objectsender, DataGridRowEventArgs e) {Db_lsyjbinfo Binddata=(Db_lsyjbinfo) E.row.datacontext; TextBox btn= Dg_source2. columns[0]. Getcellcontent (E.row). FindName ("TB") asTextBox;//Locate this column in the previous year if(BINDDATA.ZBBM = ="XJL") btn. IsReadOnly=true; }
Casually say, the line loading is very useful, but the specific control of each row of the table or a row of a column of a child control, we need to do a good job of positioning, we need to accumulate control positioning of the effort!
Like what:
DataGridCell AA = Dg_source2. columns[0 as DataGridCell; // navigate to a specific cell (standard column)
First summarize to this, learn and accumulate ha.
Silverlight uses the DataGrid row Load event to dynamically control the row and column display