Silverlight uses the DataGrid row Load event to dynamically control the row and column display

Source: Internet
Author: User

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

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.