Home Forums WPF controls Xceed DataGrid for WPF Accessing individual Data Cells

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

    Hi,
    In our Project,after displaying the data grid using tableview, We are in need to access the Data cells for some validation purpose.
    How is it possible ? Please explain this with some code.

    Regards

    Imported from legacy forums. Posted by Britto (had 1229 views)

    Xceed Support
    Member
    Post count: 5658

    You can access a DataCell in the following manner:

    Xceed.Wpf.DataGrid.DataRow row = this.MyGrid.GetContainerFromItem( this.MyGrid.CurrentItem ) as Xceed.Wpf.DataGrid.DataRow;

    row.Cells[ 0 ]…..

    Keep in mind that only the containers for data items that are in the viewport are realized; therefore, it is possible that you get null when using the GetContainerFromItem if the data item is not in the viewport.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 2950 views)

    User (Old forums)
    Member
    Post count: 23064

    Is there a possibility to get the displayed value of a Cell instead of the index if the cell is templated with a ComboBox?

    I tried two ways:

     – via DataRow (System.Data):

                DataRow row1 = dataGridControl.Items[0] as DataRow;
                row1.ItemArray[0].ToString();

     – via Xceed Row:

               Xceed.Wpf.DataGrid.DataRow row2 = dataGridControl.GetContainerFromItem(dataGridControl.Items[0]) as Xceed.Wpf.DataGrid.DataRow;
                //Xceed.Wpf.DataGrid.DataRow row2 = dataGridControl.Items[0] as Xceed.Wpf.DataGrid.DataRow;
                row2.Cells[0].ToString();

     

    The second variant worked only for displayed rows. I really don’t get the sense of Xceed Row and Xceed DataRow, displaying only visible rows in viewport. But that’s not the point:

    Does anybody know a way to display this?

     

    greets,

    Matt

    Imported from legacy forums. Posted by Matt Kay (had 908 views)

    User (Old forums)
    Member
    Post count: 23064

    Can anybody help me, or even tell me if it’s possible or not, please?

     

    greets

    Matt

    Imported from legacy forums. Posted by Matt Kay (had 598 views)

    Xceed Support
    Member
    Post count: 5658

    Xceed.Wpf.DataGrid.DataRows are containers that are created only of the data items that are displayed in the viewport; therefore, you will not be able to access the Cells in the Xceed DataRows in the way you would like. In this case, your best option would be to go through the data source and access the System.Data rows instead.

    That said, these values will represent the IDs and not the displayed values. I suggest you take a look at the  ID/Value mapping example in my documentation download folder:

    ID/Value mapping Part 1: DataTableDictionary.cs

    ID/Value mapping Part 2: ShipperIDDictionary.cs

    These examples demonstrate how to display a value rather than an ID in a combobox and should help you get the value from the ID as well. 

    Imported from legacy forums. Posted by Jenny [Xceed] (had 464 views)

    User (Old forums)
    Member
    Post count: 23064

    If I may make a suggestion regarding post #9569…You may wish to make it a sticky with a title of “How to access data in the current row.” Just use the few lines of code that are in the post.  The other method I found in the posts doesn’t work with the WPF grid.

    Imported from legacy forums. Posted by Jon (had 510 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

     I have an additional question:

    How do I get access to DataRow which is not in the ViewPort respectively how to bring it into ViewPort?

    This one doesn’t work for a row [i] which is not in the viewport. tmp is always null:

     

    BringItemIntoView(Items[i]);

    DataRow tmp = dgc.GetContainerFromItem(Items[i]) as DataRow;

     

    greets,

    Matt

     

    Imported from legacy forums. Posted by Matt Kay (had 725 views)

    Xceed Support
    Member
    Post count: 5658

    Calling BringIntoIntoView before calling GetContainerFromItem should work. Are you getting any errors? 

    Imported from legacy forums. Posted by Jenny [Xceed] (had 409 views)

    User (Old forums)
    Member
    Post count: 23064

    HI Jenny,

    Unfortunately it doesn’t work. Something weird: BringItemIntoView return true so::

    true if the specified element was brought into view; false otherwise.

    But if it reallly would be in the ViewPort it wouldn’t be null….

    Apart from the Exception that tmp is null I don’t get any errors.

     

    What’s really funny: if I don’t try to access the container (call the GetContaionerFromItem method), then the viewport changes.

    When the error occurs, as I mentiones, it doesn’t.

    greets,

    Matt

     

    PS: Could the fact play a role, that the DataGridControl is embedded in other Controls?

    Imported from legacy forums. Posted by Matt Kay (had 561 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    I found the missing thing here:

    I have to call  UpdateLayout() after BringItemIntoView and then I may call the GetContainerFromItem().

     

    greets,

    Matt

    Imported from legacy forums. Posted by Matt Kay (had 846 views)

    User (Old forums)
    Member
    Post count: 23064

    Dear Matt,

     

       Thanks for adding that here, it helpmed me a lot.

     

    Dear  Xceed Team,

     You may want to update the documentation of BringItemIntoView() method with the inforamtion related to UpdateLayout().

     

     

    kr. 

    Imported from legacy forums. Posted by Koti (had 1693 views)

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