I am facing issues in creating a custom list view in windows forms with c#. In the listview I want one cell as text box and 3 cell as drop down box or combo box and another one cell as image button. Actually I tried to make gridview and taking cell as combobox but i am not able to bind data to the specific combobox from database. I tried creating cell from the coding like making false to auto generate column but still i was not able to bind data to combobox in grid view.
My Code:
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection db = new
SqlConnection(ConfigurationManager.ConnectionStrings["ram"].ConnectionString);
db.Open();
// String query = @"Select ItemCode from Item";
SqlCommand command = new SqlCommand("Select ItemCode from Item", db);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable dt = new DataTable();
adapter.Fill(dt);
DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
//cmb.HeaderText = "";
cmb.Name = "ItemCode";
//cmb.MaxDropDownItems = 4;
cmb.Items.Add("");
//cmb.Items.Add("False");
dataGridView1.Columns.Add(cmb);
}
How can I achieve this?
DataGridViewComboBoxColumn that you are adding does not have any items in it. Try binding some value that presents in the combobox items.