Home Forums WinForms controls Xceed Grid for WinForms Binding an Unbound Column

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14071 |

    I’m binding my grids to collections (IBindingList) and have some columns that don’t bind directly to the given object.

    Let say for example I have a person class that I’m binding to and the person class has a member class of phone. I’m binding the grid to person but I want to pull the phoneNumber property through from the phone class. I’ve tried adding an unbound column and hooking the AddingDataRow row event. My theory was that e.DataRow.Tag would contain the person object from which I could set the value of the phone column. Something along these lines:
    e.DataRow.Cells[“PhoneNumber”].value = ((Person)e.DataRow.Tag).Phone.PhoneNumber

    However the Tag property always seems to be null. Is there another way for me to access the object attached to the current DataRow? Or am I ooking at this all wrong.

    Imported from legacy forums. Posted by jallenMCA (had 2971 views)

    User (Old forums)
    Member
    Post count: 23064

    You could get the index of the DataRow, and then use that to get the object from your collection.<pre>int index = e.DataRow.Index;
    if (index >= 0 && index < myCollection.Count) {
    Person myPerson = myCollection[index];
    }</pre>

    Imported from legacy forums. Posted by Tommy (had 183 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Tommy. Here’s the rub. The unbound columns are in a detail grid. So I need access to the index of the master and the detail in order to reference the object I’m looking for. Is this possible?

    Imported from legacy forums. Posted by jallenMCA (had 255 views)

    User (Old forums)
    Member
    Post count: 23064

    I haven’t worked with DetailGrids a lot, but maybe something like this:<pre>int detailIndex = e.DataRow.Index;
    Xceed.Grid.DataRow masterRow = e.DataRow.ParentGrid.ParentDataRow;
    int masterIndex = masterRow.Index;</pre>

    Imported from legacy forums. Posted by Tommy (had 3979 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.