Populate DataGridViewComboBoxColumn runtime

Posted by ghiboz on Stack Overflow See other posts from Stack Overflow or by ghiboz
Published on 2010-06-08T12:08:30Z Indexed on 2010/06/08 12:12 UTC
Read the original article Hit count: 291

Hi all! I have this problem: I have a datagridview that reads the data from a db and I wish, for an integer column use a combobox to choose some values... I modified the column using DataGridViewComboBoxColumn type and after, on the init of the form this:

DataTable dt = new DataTable("dtControlType");
dt.Columns.Add("f_Id");
dt.Columns.Add("f_Desc");
dt.Rows.Add(0, "none");
dt.Rows.Add(1, "value 1");
dt.Rows.Add(2, "value 2");
dt.Rows.Add(3, "value 3");

pControlType.DataSource = dt;
pControlType.DataPropertyName = "pControlType";
pControlType.DisplayMember = "f_Desc";
pControlType.ValueMember = "f_Id";

but when the program starts (after this code) this message appears: error

© Stack Overflow or respective owner

Related posts about c#

Related posts about datatable