Phantomazi
Phantomazi

Reputation: 408

How to choose a default value for a DataGridView ComboBox column from the ComboBox values

So here's what I have: A DataGridView with a ComboBox cell, which is DataBound to an ArrayList of items. The ComboBox is populated properly. What I want is to set the ComboBox to one of its items after it has been populated. Is there any way to do this ? Here is the ComboBox population method:

public void PopulateAssignToComboBox(ArrayList members)
    {
        _editForm.cb_editAssignTo.Items.Clear();
        var source = new BindingSource();
        source.DataSource = members;
        col_assignedToTemplate.DataSource = source;
    }

Upvotes: 1

Views: 438

Answers (1)

Crowcoder
Crowcoder

Reputation: 11514

Set that property on the members grid's data to the value you want and the grid will sync with it. Don't manipulate UI elements programmatically, manipulate the bound data. The combobox doesn't exist unless the cell is selected anyway - it is overlayed when the cell is active. You can access the combobox in the EditingControlShowing event, but as I said, this is a poor approach to achieve your goal.

Upvotes: 1

Related Questions