Click here to Skip to main content
15,860,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a combo Box named cboProductName which display member is ProductName and value member is ProductNo
and i have a DataGridView showing productNames.

When i click on the DataGridView, I want to show the clicked ProductName in combo Box and set SelectedValue to its ProductNo.

The following code is what I tried and I know it isn't right.
C#
void gvProducts_CellClick(object sender, DataGridViewCellEventArgs e)
{
    cboProductName.SelectedItem = gvProducts["gv_col_ProductName", e.RowIndex].Value;
    txtQuantity.Text = gvProducts["gv_col_Quantity",e.RowIndex].Value.ToString();
    txtPrice.Text = gvProducts["gv_col_Price",e.RowIndex].Value.ToString();
}
Posted
v2
Comments
BillWoodruff 3-Nov-13 10:19am    
If you single-step through the code you show here, at what point do things seem "not right" ?

By the way
cboProductName.SelectedIndex=cboProductName.Items.IndexOf(cboProductName.Items.FindByValue(gvProducts["gv_col_ProductName", e.RowIndex].Value));
 
Share this answer
 
try this

For index = 0 To cmbDistibuter.Items.Count - 1
        cmbDistibuter.SelectedIndex = index
        Dim dr As DataRowView = TryCast(Me.BindingContext(cmbDistibuter.DataSource).Current, DataRowView)
        If dr(1).ToString() = "your value" Then
            Exit For
        End If
    Next
 
Share this answer
 
v2
Comments
Richard MacCutchan 22-Jan-17 3:54am    
Please do not resurrect old questions; this one is over three years old.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900