0

I'm Working on a windows form GUI that has a dataGridView. In dataGridView I've two columns. The first Column Type is a ComboBoxColumn for Insurance id and name and second one is Text box for insurance code number. ComboBox Column's Datasource is already set and works.
here is code on form load :

DataGridViewComboBoxColumn Cb = new DataGridViewComboBoxColumn();
DataTable dt = new DataTable();
dt = _clsT.Fill_In_DataTable("SELECT insuranceId, insuranceName FROM insurance", false);
Cb.DataSource = dt;
Cb.Name = "insurance";
Cb.DisplayMember = "insuranceName";
Cb.ValueMember = "insuranceId";
dgv.Columns.Insert(0, Cb); 
dgv.Refresh();

after loading form i can fill dgv(DataGridView) Rows From combobox items and at last i want get all row's information with clicking on a button.
here is my code for getting rows data on btn click event

if (dgv.Rows.Count > 0)
{
   for (int i = 0; i < dgv.Rows.Count; i++)
   {
      lst1.Items.Add(dgv.Rows[i].Cells[0].Value.ToString());
      lst2.Items.Add(dgv.Rows[i].Cells[1].Value.ToString());
      //lst3.Items.Add(dgv.Rows.Cell[0] get displayMember.ToString()  ) //what i must to do?

   }
 }

ok from here i can get insuranceId and insuranceCodeNumber but how to get displayMembers ? please help me ... thanks

1 Answer 1

2

try this

dgv.Rows[i].Cells[0].FormattedValue.ToString();
dgv.Rows[i].Cells[1].FormattedValue.ToString();
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.