Default Value in comobobox column editor

6 posts, 2 answers
  1. Jose
    Jose avatar
    3 posts
    Member since:
    Sep 2011

    Posted 07 Sep 2011 Link to this post

    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.
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 08 Sep 2011 Link to this post

    Hello Jose,

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

    Best Regards,
    Emanuel Varga
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jose
    Jose avatar
    3 posts
    Member since:
    Sep 2011

    Posted 08 Sep 2011 Link to this post

    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.

  5. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 08 Sep 2011 Link to this post

    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
  6. Jose
    Jose avatar
    3 posts
    Member since:
    Sep 2011

    Posted 08 Sep 2011 Link to this post

    Thanks a lot Emmanuel
  7. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 08 Sep 2011 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready