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

RadGridView cell collection

2 Answers 149 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Customer Care Systems
Top achievements
Rank 2
Customer Care Systems asked on 08 Sep 2016, 07:18 PM

When I select a row in a RadGridView (as shown below)

    private void gridviewServiceTraceWatchList_SelectionChanged(object sender, SelectionChangeEventArgs e)
        {

            txtBillTo.Text = e.AddedItems[0].ToString();

        }


I get: “ServiceTrace.WPFApplication.CIPService.ServiceTraceWatchListData”

I’ve tried everything I know and looked and nothing works. Can anyone tell me what I’m missing? It has to be simple and I'm overthinking it. I just want to get a single field item from a row of data.

 

Thanks in advance.

 

J

2 Answers, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 09 Sep 2016, 01:01 PM
Hello,

The AddedItems collection of the SelectionChangeEventArgs returns a collection of objects (single object if SelectionMode is Single) of the type of the bound collection. In this case, I assume your ItemsSource consists of objects of type ServiceTraceWatchListData and thus calling the ToString() method, produces the described result.

If you have set RadGridView's SelectionUnit to Cell, you can get the value of the field for the last selected cell by handling the SelectedCellsChanged event like so:

private void radGridView_SelectedCellsChanged(object sender, GridViewSelectedCellsChangedEventArgs e)
{
    var cell = e.AddedCells[0];
    var field = cell.Item.GetType().GetProperty(cell.Column.UniqueName).GetValue(cell.Item, null);
    MessageBox.Show(field.ToString());
}

Please let me know whether such an approach would work for you.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Customer Care Systems
Top achievements
Rank 2
answered on 14 Sep 2016, 06:50 PM

Awesome. I was overthinking it    o_o

 

Thanks.

Tags
GridView
Asked by
Customer Care Systems
Top achievements
Rank 2
Answers by
Dilyan Traykov
Telerik team
Customer Care Systems
Top achievements
Rank 2
Share this question
or