Rebinding DGV Combobox Column. C#.Net 2008, Framework 3.5.
-
I have a dgv that's bound to a table tblQuoteItems. One of the columns of the dgv is ItemID which is a combobox column. Its value is obtained from ItemID field of tblQuoteItems. Before binding the dgv, the ItemID column is populated from tblItems table containing fields ItemID and Item. The ItemID column of the dgv has ItemID as valuemember and Item as displaymember. Now is it possible to rebind only the ItemID column while keeping the dgv state intact i.e. without rebinding the dgv? For example I open up a lookup form and modify tblItems table, then I want the effect to be acted upon the ItemID column of the dgv without affecting the state of the dgv. I recalled BindDGVComboBox method defined underneath after modifying the values of tblItems but of no avail. Please help. My code follows:
SqlConnection con;
string strSql;
SqlDataAdapter da;
DataTable dt;
SqlCommandBuilder cb;
BindingSource bs = null;void PopulateDgv()
{
LineID = new DataGridViewTextBoxColumn();
QuoteID = new DataGridViewTextBoxColumn();
ItemID = new DataGridViewComboBoxColumn();
LookupItems = new DataGridViewButtonColumn();
Quantity = new DataGridViewTextBoxColumn();
UnitPrice = new DataGridViewTextBoxColumn();
LineTotal = new DataGridViewTextBoxColumn();dgvItems.Columns.Clear(); dgvItems.DataSource = null; dgvItems.Columns.AddRange(new DataGridViewColumn\[\] {LineID, QuoteID, ItemID, LookupItems, Quantity, UnitPrice, LineTotal }); LineID.Name = "LineID"; LineID.DataPropertyName = "LineID"; LineID.Visible = false; QuoteID.Name = "QuoteID"; QuoteID.DataPropertyName = "QuoteID"; QuoteID.Visible = false; ItemID.Name = "ItemID"; ItemID.DataPropertyName = "ItemID"; LookupItems.Name = "LookupItems"; LookupItems.DataPropertyName = "LookupItems"; LookupItems.DefaultCellStyle.NullValue = "..."; LookupItems.Resizable = DataGridViewTriState.False; Quantity.Name = "Quantity"; Quantity.DataPropertyName = "Quantity"; UnitPrice.Name = "UnitPrice"; UnitPrice.DataPropertyName = "UnitPrice"; LineTotal.Name = "LineTotal"; LineTotal.DataPropertyName = "LineTotal"; LineTotal.ReadOnly = true; BindDGVComboBox(ItemID, "Select ItemID,Item From tblShopItems Order By ItemID", "ItemID", "Item"); if (bs == null) { bs = new BindingSource(); } if (dt == null) { dt = new DataTable(); } strSql = "Select LineID,QuoteID,ItemID,'...' As LookupItems,Quantity,UnitPrice,Lin