How to do DataBinding with columns in RadGridView table

6 posts, 0 answers
  1. Robert
    Robert avatar
    6 posts
    Member since:
    Jun 2013

    Posted 10 Jul 2014 Link to this post

    Hi,

    I have a RadGridView that I want to implement databinding based on the cells selected in a column.  Currently, the row data is bound to the ItemsSource for databinding on the rows.  I want to be able to allow the user to select multiple cells within a column and once the user changes the value in one cell, the change will be applied to all the other cells selected in the column.   How can I implement that?  I have enabled SelectionMode=Extended and SelectionUnit=Cell to allow selection(s).

    Thank you,
    Robert Quan
  2. Yoan
    Admin
    Yoan avatar
    1214 posts

    Posted 15 Jul 2014 Link to this post

    Hi Robert​,

    You can use GridView's CellEditEnded event and execute the following code:
    private void clubsGrid_CellEditEnded(object sender, GridViewCellEditEndedEventArgs e)
            {
                if (e.NewData != null && e.EditAction == GridViewEditAction.Commit)
                {
                    foreach (GridViewCellInfo cellInfo in clubsGrid.SelectedCells)
                    {
                        Club item = cellInfo.Item as Club;
                        item.Name = e.NewData.ToString();
                    }
                }
            }

    I hope this helps.

    Regards,
    Yoan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. Robert
    Robert avatar
    6 posts
    Member since:
    Jun 2013

    Posted 18 Jul 2014 in reply to Yoan Link to this post

    Hi Yoan,

    Thank you for the help and code snippet.  I have a couple a questions and pardon my ignorance but what is the "Club" in reference to?  I have a DataClass which is bound to the  data for each row; is this what "Club" reference or something else?  I've put in the above mentioned code (minus the two lines within the foreach loop) and the necessary CellEditEnded assignment in the xaml file.  However, the e.NewData is always Null thus it will never enter the foreach loop.

    Thanks
    Robert
  4. Robert
    Robert avatar
    6 posts
    Member since:
    Jun 2013

    Posted 20 Jul 2014 in reply to Robert Link to this post

    Joan,

    Just a clarification and update.  I was able to use your code snippet and it does work for textblock cells in a column.  However as partially mentioned in my previous post, if the column cells are Combox type the NewData data member is always null.  Is there a reason for this?

    Thanks,
    Robert
  5. Robert
    Robert avatar
    6 posts
    Member since:
    Jun 2013

    Posted 20 Jul 2014 in reply to Robert Link to this post

    Yoan,

    It seems like NewData is never set correctly.  For the textblock cells in the column, the newData is non-null but is never the set to the cell in the selection with the changed value.   Is there some additional binding setup that is required?

    Thanks,
    Robert
  6. Yoan
    Admin
    Yoan avatar
    1214 posts

    Posted 23 Jul 2014 Link to this post

    Hello Robert,

    Generally, the NewData property allows you to access the updated data. Thus if you do not have new/updated data, the NewData will be null. 

    I am sending you a sample project which demonstrates the suggested approach. Please give it a try and let me know how it works for you.

    Regards,
    Yoan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top