Synching a DatagridviewComboBox bound to an object list and a Datagridview bound to a different obje

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am writing an Invoice Tracking app. In the Forms loading event, I create a set of lists used by the app, including a list of LineItems and a list of Products, both of which are used in the datagridview. Then I set the DataSource of two BindingSources to
those two lists. I then create a series of datagridviewcolumns, including a combobox column:
<span style="line-height:100%; font-family:Courier new <span style="color:#0000ff With<span> DescCol
bsProduct.DataSource was set earlier to "ProdctList" which is a list of Products
<span> <span>.DataSource = bsProduct

<span> <span>.DisplayMember = <span style="color:#a31515 "Name"<span>
<span> <span>.ValueMember = <span style="color:#a31515 "ID"
<span> <span>.Name = <span style="color:#a31515 "Description"<span>
<span> <span>.DisplayIndex = 2
<span> .ReadOnly = <span style="color:#0000ff False<span>
<span> .HeaderText = <span style="color:#a31515 "Description"<span>
<span> .HeaderCell.Style.Alignment = <span style="color:#2b91af DataGridViewContentAlignment<span>.MiddleCenter
<span> .DisplayStyle = Windows.Forms.<span style="color:#2b91af DataGridViewComboBoxDisplayStyle<span>.Nothing
<span><span style="color:#0000ff End<span> <span style="color:#0000ff With<br/>

and add these columns to the datagridview. Then I set the datasource of the dgv to the appropriate BindingSource (ie bsInvcItem whose Datsaource=InvcItemList which is a list of LineItems)<span style="color:#0000ff <br/>

When the form is loaded, the dgv displays the items in the InvcList with all of the columns (except the ComboBoxColumn) displaying their correct values. The combobox columns are blank. If I select a cell in the combobox column, it displays a combobox that
does have a list of Products, but the loading of the form (and the datagridview) doesnt set the combobox column, which I realize is due to the fact that the combobox column is not bound to the InvcItem list. My question is how do set the combobox columns
selected index column before the form is displayed? Which datgridview event do I need to process in order to set the comboboxs SelectedIndex=FindStringExact( InvcItemList(e.RowIndex),Product.Name) <hr class="sig VS2010, VB.NET, SQL Server2012

View the full article
 
Back
Top