Question

I made a function like this:

public DataTable getMtrBcdMod()
{
    DataSet ds = new DataSet();
    string query = "select pMtrBcdMod, sMtrBcdMod from dtMtrBcdMod ";

    SqlCommand cmd = new SqlCommand(query, DatabaseConnection);
    SqlDataAdapter dap = new SqlDataAdapter();
    dap.SelectCommand = cmd;
    dap.Fill(ds);

    return ds.Tables[0];
}

and I wish designtime, editing a datagridview, add a DataGridViewComboBoxColumn that points at the datasource the DataTable returned by the function, using ValueMember pMtrBcdMod and sMtrBcdMod as DisplayMember..

how can I do this?

thanks

Était-ce utile?

La solution

You need to attach the combobox to a column in your DataTable by assigning the DataPropertyName of your custom combo box to the chosen column, ie, "Column A".

You then hide the original column from display, but all changes that are made in your combobox will be reflected in the underlying datatable column also.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top