Click here to Skip to main content
16,021,169 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void dgridregistration_CellClick(object sender, DataGridViewCellEventArgs e)
    {

    if (e.RowIndex >= 0)
        {
        DataGridViewRow row = this.dgridregistration.Rows[e.RowIndex];
        txtmemfname.Text = row.Cells["fname"].Value.ToString();
        txtmemmname.Text = row.Cells["mname"].Value.ToString();
        txtmemlname.Text = row.Cells["lname"].Value.ToString();
        rchtxtmemaddress.Text = row.Cells["address"].Value.ToString();
        cmbmemstate1.Text = row.Cells["state_name"].Value.ToString();
        cmbmemcity1.Text = row.Cells["city_name"].Value.ToString();
        txtbdate.Text = row.Cells["bdate"].Value.ToString();
        txtmempincode.Text = row.Cells["pincode"].Value.ToString();
        cmbmemoccupation1.Text = row.Cells["occupation"].Value.ToString();
        cmbmembgroup1.Text = row.Cells["blood_id"].Value.ToString();
        }
    }

This is my code to populate the textboxes with datagriedview values. but in state and city, i want to display the values of other states and cites stored in a table name state and city.

so please help me out..
Posted
Updated 29-May-14 9:56am
v2
Comments
gggustafson 29-May-14 15:59pm    
Are the state and city cells in the DataGridView ComboBoxes or are they TextBoxes? If they are TextBoxes, is it that you want to add any new value to the appropriate table?
Member 9671810 30-May-14 8:48am    
yup. i mean they are just read only in datagridview and i have made a table layout by its side and have made all the controls same as registration page

1 solution

You are treating the combobox like a textbox. You need to get a list of states and cities from the underlying data source and bind that to the datasource of the comboboxes.

The when you select a row in the DGV you set the SelectedValue of the combobox to the text from the DGV.
 
Share this answer
 
Comments
Member 9671810 30-May-14 8:51am    
i did this.. but it does not show the selected value.
Member 9671810 30-May-14 14:33pm    
help me soon.. plz....

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