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

RadGridView - Default option in GridViewComboBoxColumns

5 Answers 312 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 22 Feb 2010, 01:53 PM

[Completely new with Telerik]
Hi

I have a Category column in Employee Table as of type GridViewComboBoxColumn and i have assigned a datasource to it.  
The values of this column can be "Male" or "Female". The datasouce contains these two values.

While adding new record I want to pick up 1st available value in datasource as default selected.

How can i do this?

 

Regards

Raghu.

5 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 25 Feb 2010, 04:49 PM
Hello Lee,

Thank you for the question. Currently RadGridView does not support setting default values for combo box column. However, you can implement the desired functionality by creating custom editor. Please, consider the following code:
        void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
        {
            if (e.EditorType == typeof(RadComboBoxEditor))
            {
                e.EditorType = typeof(CustomComboEditor);
            }
        }
  
  
      
class CustomComboEditor : RadComboBoxEditor
    {
        public override void BeginEdit()
        {
            base.BeginEdit();
  
            RadComboBoxEditorElement editorElement = this.EditorElement as RadComboBoxEditorElement;
  
            if (editorElement.SelectedIndex == -1)
            {
                editorElement.SelectedIndex = 0;
            }
        }
    }

Do not hesitate to contact me again if you have any other questions.

Kind regards,
Martin Vasilev
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
Bob
Top achievements
Rank 2
answered on 18 Jun 2012, 09:06 PM
I was curious to know if there has been an update to the control in order to assign a default or "first" item in the bound gridviewComboBoxColumn?

Thanks
Bob
0
Bob
Top achievements
Rank 2
answered on 18 Jun 2012, 09:07 PM
I was curious to know if there has been an update to the control in order to assign a default or "first" item in the bound gridviewComboBoxColumn?

Thanks
Bob
0
Stefan
Telerik team
answered on 21 Jun 2012, 10:12 AM
Hello Bob,

Thank you for writing.

In the latest version, the combo column uses RadDropDownList editor and selecting a default item for it will not require overriding the whole editor. You can just use the CellEditorInitialized event handler:
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
    if (editor != null)
    {
        RadDropDownListEditorElement element = editor.EditorElement as RadDropDownListEditorElement;
        element.SelectedIndex = 1;
    }
}

I hope this helps.

 

All the best,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Bob
Top achievements
Rank 2
answered on 21 Jun 2012, 02:33 PM
Just what I was looking for - thanks!
Tags
GridView
Asked by
Lee
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Bob
Top achievements
Rank 2
Stefan
Telerik team
Share this question
or