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

[Solved] Setting a different Select Item Value in GridViewComboBoxColumn column

6 Answers 192 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Adriano
Top achievements
Rank 1
Adriano asked on 28 Jan 2013, 06:57 PM
Hi,

Is there any way I can set the Selected Item to a different value from the main collection that bind the GridView?

I have a gridview, in this gridview I have a GridViewComboBoxColumn, this is bind by a collection.

At first user select an item in combo, then user edit other columns in the grid and get back to the first combo column, based on the data of the row, I'd like to set another selected item in the combo once the user opens it, but without changing grid collection. Is this possible?

Thanks,
Adriano Gaspar.

6 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 29 Jan 2013, 09:22 AM
Hello Gaspar,

Based on your description I am sure we can think of a descent solution. Can you give an example of the expected behavior with some imaginary data or alternatively  let me know the structure of your source data  so I can be more specific in my answer.

Kind regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Adriano
Top achievements
Rank 1
answered on 29 Jan 2013, 01:09 PM
I good exemple is this:

I have a GridViewComboBoxColumn in Grid View with the following data:

  • Option 1
  • Option 2
  • Option 3
  • Option 4
  • Option 5
  • Option 6

The user fill data in another cells, and return to this combo (which may or may not have somehing selected ), and I want to programatically set Option 4 as the selected in the combo.

Thanks,
Adriano Gaspar.



0
Pavel Pavlov
Telerik team
answered on 01 Feb 2013, 09:55 AM
Hello,

Fur such scenario I may recommend the following approach :

1. Instead of GridViewComboBox column , use a regular GridViewDataColumn
2. Using the CellTemplate property of the column , place a combobox of yours inside the cell. This way you have the power to define how the combo is bound and what does it change on selection changes.
3. Use the GotFocus event of the combo in order to perform the automatic selection when the user returns to the combo cell.

Regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Adriano
Top achievements
Rank 1
answered on 01 Feb 2013, 12:10 PM
Pavel,

This seems a reasonable solution, but in my case, I have some validations, and some features of GridViewComboBox which I tried some time ago to replicate on Combobox but not all behavior was exactly the same, and if I do this changes will I'll have to retest lots of things.

Do you have any other option? What if I inherits GridViewComboBox and add some kind of property or the GotFocus event?

Thanks,
Adriano Gaspar.
0
Pavel Pavlov
Telerik team
answered on 01 Feb 2013, 01:10 PM
Hi,

Yes this sounds like a reasonable approach - in case you inherit  the GridViewComboBoxColumn, you can override the CreateCellEditElement method and add your custom logic there.

However I was offering the CellTemplate approach , as you mentioned you need to set another value as selected value in the combo, with out the change being reflected in the source object.

The Combo column relies on the two way binding to the source object in order to display the right values. This binding also means , that when you set programmatically another selected item , the change would reflect into the bound item .

Maybe I am misunderstanding the requirement " ... without changing grid collection " .

Regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Adriano
Top achievements
Rank 1
answered on 27 Feb 2013, 08:15 PM
HI, we used another approach.

Thanks for your efforts.
Tags
GridView
Asked by
Adriano
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Adriano
Top achievements
Rank 1
Share this question
or