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

GridView cells containing KeyValuePair entries (in C# CodeBehind)

3 Answers 273 Views
GridView
This is a migrated thread and some comments may be shown as answers.
DA
Top achievements
Rank 1
DA asked on 24 Oct 2012, 12:15 PM
Hi everyone,

I'm using a RadGridView in a form to store some values that the user selects in the form.
So the process is something like that:
1. the user selects a value from a dropdownlist and types a text in a TextBlock
2. the user clicks on button Add
-> the values of the fields will be copied in a gridview (that the user can also see)
3. the user clicks on a save button
  -> the gridview will be browsed and each row will be stored in the DB

Now my problem is the value that gets selected from a dropdownlist. This list displays string values but behind they are keys.
The user selects a string value "ABC" and sees that exact value in the gridview. But on save I need to save the corresponding key.

So my question is, how can I manage to store the Value and the Key in a cell but allowing the user to see only the Value.
I tried to do that with a KeyValuePair but then both are displeyed in the cell: [23, ABC].

I'm using a class of DisplayAttributes to define the columns of the gridview, so i don't do anything in the xaml file.

Thank you for any suggestion.

DA.

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 24 Oct 2012, 12:26 PM
Hello,

You could place a GridViewComboBoxColumn (or a DropDownList inside column's CellTemplate) in the RadGridView to keep track of the selected values from the DropDownList. Please check our online documentation.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
DA
Top achievements
Rank 1
answered on 24 Oct 2012, 12:36 PM
Hi Didie,

Thanks for your quick answer.
I cannot replace the current form i have by the combobox in the gridview, the user can only fill up the form and see the values in the gridview, which is in readonly mode :/
0
Pavel Pavlov
Telerik team
answered on 25 Oct 2012, 01:16 PM
Hello,

You said "tried to do that with a KeyValuePair but then both are displayed in the cell: [23, ABC]."

In order to display only the value ( without the key ) , you will just need to append ".Value"  to the path of the DataMemberBinding in the column in question.  Currently the Path points to the object itself thus invoking its "ToString()" method . If you fix the path as stated above , it will show the Value , instead of calling the ToString() of the KeyValuePair.

Let me know if you find any trouble with this approach.

Kind regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
DA
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
DA
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or