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

Default Value in comobobox column editor

5 Answers 130 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jose
Top achievements
Rank 1
Jose asked on 07 Sep 2011, 01:03 PM
I have a combobox populated with a dataset, and i want to show in the column editor (before enter a value) a value of the items of the combo.

How can i do this.

Thanks a lot.

5 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 08 Sep 2011, 07:43 AM
Hello Jose,

Could you please try to be a bit more clear on what you are trying to accomplish?

Best Regards,
Emanuel Varga
0
Jose
Top achievements
Rank 1
answered on 08 Sep 2011, 08:29 AM
Hello:
i want that the combobox of the grid (in the zone "click here to add a new row") shows a default value.
For example, the combobox column of my grid shows all of users of my application. When the application starts, the user have to log in with username and password. Then, if the user goes to the grid, i want that the combobox column of the grid shows the username logged by default (before editing grid in the "adding row zone").

Thanks a lot.

0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 08 Sep 2011, 11:44 AM
Hello Jose,

You just need to handle the CellEditorInitialized event and perform some of the following checks there:
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    if (e.Row is GridViewNewRowInfo)
    {
        if (e.ColumnIndex == 0)
        {
            var editor = e.ActiveEditor as RadDropDownListEditor;
            if (editor == null)
            {
                return;
            }
 
            var editorElement = editor.EditorElement as RadDropDownListEditorElement;
            editorElement.SelectedIndex = 12;
        }
    }
}

and inside you can set whatever you want to the editorElement.SelectedText or SelectedItem or anything you would normally do to select an item if you had access to the dropdown itself.

Best Regards,
Emanuel, Varga
0
Jose
Top achievements
Rank 1
answered on 08 Sep 2011, 12:27 PM
Thanks a lot Emmanuel
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 08 Sep 2011, 12:29 PM
Glad to be able to help,

If you have any more questions please just let me know, and if the question has been solved, please mark the question as answered, so that others can find the answers to their questions faster.

Best Regards,
Emanuel Varga

WinForms MVP
Tags
GridView
Asked by
Jose
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Jose
Top achievements
Rank 1
Share this question
or