Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Datagridview comboboxcolumn value is cleared when cell is exited
 

Datagridview comboboxcolumn value is cleared when cell is exited

Hi
I have a datagridview control displayed on a form which is populated by a datatable created by a stored procedure. I dynamically add a datagridviewcomboboxcolumn to the datagridview control and populate each of the combobox's with a list which is dependant on another field in the underlying datatable. the user can then select an option for each row in the datagridview control. All this works perfectly except for the last row of the datatable. The user can select an option from the list without issue but as soon as the cell is exited the valuemember of the lastrow combobox returns zero.

Any help would be greatly appreciated.
LRBannister  Tuesday, July 21, 2009 4:41 PM

Hi,

Sorry. I am not able to reproduce this issue. Could you please show us the code?


I use the following code to test.

private void Form1_Load(object sender, EventArgs e)

{

DataTable dt01 = new DataTable();

dt01.Columns.Add("col01");

dt01.Columns.Add("col02");

dt01.Rows.Add("1","aa");

dt01.Rows.Add("2","bb");

DataTable dt02 = new DataTable();

dt02.Columns.Add("ID");

dt02.Columns.Add("Name");

dt02.Rows.Add("1", "aa");

dataGridView1.AutoGenerateColumns = false;

dataGridView1.DataSource = dt02;

DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();

cmb.DataSource = dt01;

cmb.DataPropertyName = "ID";

cmb.DisplayMember = "col02";

cmb.ValueMember = "col01";

dataGridView1.Columns.Add(cmb);

}

private void button1_Click(object sender, EventArgs e)

{

Console.WriteLine(dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[0].Value.ToString());

}

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Sunday, July 26, 2009 8:23 AM

We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Thursday, July 30, 2009 2:47 AM

You can use google to search for other answers

Custom Search

More Threads

• Getting DataGrid cell value or selecting first Row
• SQLDataSource - setting parameter values in code
• DataGridView - Formatting the Selected Row
• How to hide controls for certain DatagridView Cells?
• BindingSource with embedded array - how to?
• GridViewRowEventArgs versus EventArgs?
• ListBox Data Binding and Selection Set Accessing
• How to customize DataGridView in DataGridViewCell
• Using Dataset from another form
• BackgroundWorker and BindingSource Threading question