populate datagridview based on combobox selection?

raviteja

Member
Joined
Oct 15, 2019
Messages
8
Programming Experience
Beginner
i tried in this way to populate datagridview based on combobox selection,but it is not working,can anyone help me
C#:
if (metroComboBox1.Text == "Header")
            {
                DataRow[] rows = Common._dataSet.Tables["oSelectedFields"].Select("Category='H'");
                foreach (DataRow r in rows)
                {
                   
                    foreach (DataGridViewRow dr in dtgSelectedFieldList.Rows)
                    {
                       
                            DataRow gv2dr = dt.NewRow();
                            gv2dr["Description"] = dr.Cells["Description"].Value.ToString();
                            gv2dr["FieldType"] = dr.Cells["FieldType"].Value.ToString();
                            gv2dr["FieldID"] = dr.Cells["FieldID"].Value.ToString();
                            //Add slected rows in second datagridview
                            dt.Rows.Add(gv2dr);
                    }
                }
           dtgSelectedFieldList.DataSource = dt;
 
What exactly is not working? Are you getting an exception, if so what is the exception? If you aren't getting an exception, can you describe what behavior you were expecting, and what behavior you are currently seeing. Have you stepped through your code with a debugger? What values were you expecting to see while stepping through, and what were expecting to see?
 
I have combobox with Header,Row,Header Udf and row udf.based on combobox selection I want to populate the datagridview with Header,row,h UDF and r UDF fields
 
Okay. That tells us what you want to do. That still doesn't tell us what behavior you are seeing.
 
What are you seeing when you run your program?
What were you expecting to see in when you run your program?
Are you getting error messages?
 
i tried in this way to populate datagridview based on combobox selection,but it is not working,can anyone help me
This doesn't tell us anything.

If you want help, I suggest putting some time and effort into explaining the problem you are facing. We are not mind readers.

How is it not working?
 

Latest posts

Back
Top Bottom