AmrMohammed 0 Junior Poster


I'm making a WindowsFrom for an invoice and I'm having a problem with datagridview control that consists of two datagridviewcombobox columns and another two datagridviewtextboxcolumn

First of all I build the datagridview within run-time, I mean adding its columns within run-time


I restored the product ID and the product name for each product in a datatable then bind the datagridviewcomboboxcolumn1 to this datatable.

datagridviewcomboboxcolumn1.DataSource = datatable1;
datagridviewcomboboxcolumn1.DisplayMember = "ProductID";
datagridviewcomboboxcolumn1.ValueMember = "ProductName";

When I select a product name from the datagridviewcomboboxcolumn1, first I restored the unit measure ID and the unit measure name in a datatable but in this case only the units of measure related to the selected product from the datagridviewcomboboxcolumn1 not for each unit measure within database, and again bind the datagridviewcombobox2 to the datatable contains the units of measure.

datagridviewcomboboxcolumn2.DataSource = datatable2;
datagridviewcomboboxcolumn2.DisplayMember = "UnitID";
datagridviewcomboboxcolumn2.ValueMember = "UnitName";

The problem occurs when I try to read an invoice detials data. The InvoiceDetails table within database contains InvoiceNumber, ProductID, UnitID, Quantity and UnitPrice columns. When I type the invoice number within a textbox control. I pass this number to a method that reads data from the InvoiceDetails table using a SqlDataReader.

sqlDataReader = sqlCommand.ExcuteReader();


datagridview[0, RowIndex].Value = sqlDataReader[0].ToString();
datagridview[1, RowIndex].Value = sqlDataReader[1].ToString();
datagridview[2, RowIndex].Value = sqlDataReader[2].ToString();
datagridview[3, RowIndex].Value = sqlDataReader[3].ToString();

The problem is that instead of finding the the product name within the datagridviewcomboboxcolum1 and the unit measure name within the datagridviewcomboboxcolumn2 I find the product ID and the unit measure ID and an Exception is thrown