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

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top