View previous topic :: View next topic |
Author |
Message |
jmihelich
Joined: 18 May 2012 Posts: 4
|
Posted: Tue Oct 29, 2013 6:12 am Post subject: Using data binding change icon based on cell content |
|
|
I have a tree where I have some data stored in a DataTable. I use data binding to get the data into the virtual tree. I also use the design time editor to set an icon for each of my datatables (after using auto generate)
Say I have a table like:
[row_id[name][state]
0 one 1
1 two 2
2 three 1
What I would like to do is have the tree change the icon based on the value in [state]. I display both image and text in the cell can't see how to change the icon, just for this cell to a new one based on the 'state' |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Oct 29, 2013 7:04 am Post subject: |
|
|
You have to handle the GetRowData event and set the image/icon programmatically as shown below:
Code: | private void _virtualTree_GetRowData(object sender, GetRowDataEventArgs e)
{
// get the default binding for the given row and use it to populate the row data
//
RowBinding binding = _virtualTree.GetRowBinding(e.Row);
binding.GetRowData(e.Row, e.RowData);
// now assign the icon/image based on your program condition
//
if (e.Row.Item is OrderDataSet.CustomersRow)
{
OrderDataSet.CustomersRow customer = e.Row.Item as OrderDataSet.CustomersRow;
if (customer.ContactName.StartsWith("A"))
{
e.RowData.Image = _myImage;
}
}
} |
This code is a modification to the DataSetBrowser sample and sets the image for all customers with ContactName starting with A to a different image. _________________ Infralution Support |
|
Back to top |
|
|
|