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

How to: Retrieve value of cell in selected row

7 Answers 204 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 09 Jul 2010, 06:54 AM
Hello everybody

After doing researches in all available source I still can not accomplish this probably trivial task. I would like to read the values of various cells of the row which is selected. The sample I found in this forum deals with a business object (Person). I'd expected something like:

myValue = gridview.selectedRow.Columns("NameOfThisColumn")

Thanks for your help in advance

Michael Lutz
BITsoft

7 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 09 Jul 2010, 06:55 AM
Hi Michael,

 You can cast SelectedItem property to your type and access directly desired property. For example:

var city = ((Customer)RadGridView1.SelectedItem).City;

All the best,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michael
Top achievements
Rank 1
answered on 09 Jul 2010, 07:54 AM
Thank you Vlad for your prompt answer

I do not have a type. All I want is to retrieve the cell value and show it in a text box. Do you have a code snippet in VB.NET. I am sorry for not seeing the easiness of your answer but since I am very new to WPF and also have strong paradigms on VB6 and DAO, it is very hard to complete even trivial tasks ;-)

thanks in advance

Michael Lutz
BITsoft
0
Vlad
Telerik team
answered on 09 Jul 2010, 08:14 AM
Hello Michael,

Generally you always have a type :). How the grid is bound in your case? Here is the same code for VB.NET:

Dim city As String = CType(RadGridView1.SelectedItem, Customer).City

If you prefer you can get desired value using reflection. Please check the attached project for reference. 

Sincerely yours,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michael
Top achievements
Rank 1
answered on 09 Jul 2010, 10:17 AM
hello Vlad

thanks again, I (try to) have one last question:

>>Dim city As String = CType(RadGridView1.SelectedItem, Customer).City<<

My Gridview is bound (.timesource) to a datatable which autogenerated various columns. Let's say the column "LastName" contains the last name of a customer. This value should be read. So I assume that the right code would be:

dim LastName as string = ctype(RadGridView1.SelectedItem, ?).LastName

Is this correct and what would the equivalent for your variable "Customer" in my sample case?

(I have not looked in your sample project since I am building a WPF and not a Silverlight application and I have a tremendious timely pressure)

thanks in advance and best regards,

Michael Lutz
BITsoft
0
Vlad
Telerik team
answered on 09 Jul 2010, 10:22 AM
Hello Michael,

 Sorry for the Silverlight application - my mistake! Here is an example with DataRow:

dim LastName = CType(RadGridView1.SelectedItem, DataRow)["LastName"]

Sincerely yours,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michael
Top achievements
Rank 1
answered on 09 Jul 2010, 11:46 AM
hello Vlad

>>dim LastName = CType(RadGridView1.SelectedItem, DataRow)["LastName"]<<

my IDE is complaining the ["LastName"]". Unfortunately I can only write the German language comment of the IDE saying "Bezeichner erwartet". The is pointing to the '"' right after the [.

???

thanks for your Help and best regards,

Michael Lutz
BITsoft
0
Vlad
Telerik team
answered on 09 Jul 2010, 12:02 PM
Hello Michael,

 Sorry again! Here is the correct VB syntax:

CType(RadGridView1.SelectedItem, DataRow)("LastName")

All the best,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Michael
Top achievements
Rank 1
Share this question
or