This is a migrated thread and some comments may be shown as answers.

How to do DataBinding with columns in RadGridView table

5 Answers 188 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 10 Jul 2014, 07:07 PM
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

5 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 15 Jul 2014, 10:15 AM
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.
 
0
Robert
Top achievements
Rank 1
answered on 18 Jul 2014, 07:49 PM
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
0
Robert
Top achievements
Rank 1
answered on 20 Jul 2014, 03:58 PM
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
0
Robert
Top achievements
Rank 1
answered on 20 Jul 2014, 05:52 PM
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
0
Yoan
Telerik team
answered on 23 Jul 2014, 01:47 PM
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.
 
Tags
GridView
Asked by
Robert
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Robert
Top achievements
Rank 1
Share this question
or