Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
580
ValueListItems get Tag value
posted

Hi,

 

I have found an example how to assign a Tag value to a new ValueListItem.

 

ValueListItem valueListItem = shippersValueList.ValueListItems.Add( shipperID, shipperName );

valueListItem.Tag = dataRow;

 

How can I access Tag value from CellChange event?  

 

Thank you

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi,

    CellChange could be a bit tricky, because (depending on the Style of the column), the user could type something in the cell that is not on the list.

    In any case, you will need to get the currently selected item based on the current cell text and then get the tag from that item. Here's some quick sample code:


            private void ultraGrid1_CellChange(object sender, CellEventArgs e)
            {
                UltraGrid grid = (UltraGrid)sender;
                UltraGridCell activeCell = grid.ActiveCell;
                ValueList valueList = (ValueList)activeCell.ValueListResolved;

                if (valueList != null)
                {               
                    int selectedIndex = -1;
                    object value = ((IValueList)valueList).GetValue(activeCell.Text, ref selectedIndex);
                    if (selectedIndex >= 0 && selectedIndex < valueList.ValueListItems.Count)
                    {
                        ValueListItem selectedItem = valueList.ValueListItems[selectedIndex];
                        Debug.WriteLine(selectedItem.Tag);
                    }
                }
            }

     

Reply Children
No Data