Silverlight uses the DataGrid row loading event to dynamically control row and column display, silverlightdatagrid

Source: Internet
Author: User

Silverlight uses the DataGrid row loading event to dynamically control row and column display, silverlightdatagrid

The datagrid binding is very useful, but sometimes we often need to dynamically control rows or columns based on the model content. What should we do?

At this time, we need to use the row loading event: when loading each row of data, we can control the corresponding table display based on the data content.

For example, if we want to set the baseline color of each row to red, we can do this:

 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 also do the following:

Private void dg_source2_LoadingRow (object sender, DataGridRowEventArgs e) {db_lsyjbInfo bindData = (db_lsyjbInfo) e. row. dataContext; TextBox btn = dg_source2.Columns [0]. getCellContent (e. row ). findName ("tb") as TextBox; // locate the if (bindData. zbbm = "xjl") btn. isReadOnly = true ;}

Just put, row loading is very useful, but when we control each row of a table or a child control of a column in a row, we need to do a good job of positioning, you need to work hard to locate the control at ordinary times!

For example:

DataGridCell aa = dg_source2.Columns [0]. GetCellContent (e. Row) as DataGridCell; // locate a specific cell (standard column)

Here, we will learn and accumulate.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.