Click here to Skip to main content
15,888,037 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir,

I am creating windows application c# 2010, here i am explain my project details any one solve my problem sir.

I am using 2 two drop down list
i am select first drop down list that time values are dispaly on my data grid view with some empty rows.
check my image link[^] sir.

-------------------------------------------------------------------
After that i am select 2nd drop down list
that time i want records update on my empty row cells.
this is my second image link[^] sir,

But not fixed for 3rd and 4th rows are empty, some times 6th, 7th and 8th rows are empty.

How to create my logic sir, give me some help sir,

What I have tried:

How to bind values on data grid view empty cells using c# windows forms
Edit - OP code from a comment
is is my code, i am write this code my 2nd comboBox SelectedIndexChanged Event
C#
  SqlConnection con1 = new SqlConnection(db.Connectionstring());
  con1.Open();

  using (SqlCommand cmd1 = new SqlCommand("select * from pardetails where parname='" + comcredeb.Text + "'", con1))
  {

    using (SqlDataReader dr1= cmd1.ExecuteReader())
    {
      cmd1.CommandType = CommandType.Text;

      using (SqlDataAdapter sda = new SqlDataAdapter(cmd1))
      {
        using (DataSet ds1 = new DataSet())
        {
          if (dr1.HasRows)
          {
            bool Empty = true;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
              for (int i = 0; i < dataGridView1.Rows.Count; i++)
              {
                while (dr1.Read())
                {
                  Empty = true;
                    for (int j = 0; j < dataGridView1.Columns.Count; j++)
                    {
                      if (dataGridView1.Rows[i].Cells[1].Value != null && dataGridView1.Rows[i].Cells[1].Value.ToString() != "")
                      {
                        Empty = false;
                        break;
                      }
                    }



                    if (Empty)
                    {
                      row.Cells[1].Value = dr1.GetString(19);
                      row.Cells[1].Value = dr1.GetString(21);
                    }
                }
              }
            }

            dr1.Close();
            con1.Close();
            sda.Fill(ds1);
          }
        }
      }
    }
  }
  dataGridView1.Focus();
}
Posted
Updated 12-Jul-18 4:28am
v2
Comments
CHill60 11-Jul-18 9:04am    
You haven't shared your code so we cannot help you. The "What I have tried:" section is where you need to put the code that is causing the problem
Boopalslm 11-Jul-18 11:39am    
This is my code, i am write this code my 2nd comboBox SelectedIndexChanged Event



SqlConnection con1 = new SqlConnection(db.Connectionstring());
con1.Open();

using (SqlCommand cmd1 = new SqlCommand("select * from pardetails where parname='" + comcredeb.Text + "'", con1))
{

using (SqlDataReader dr1= cmd1.ExecuteReader())
{



cmd1.CommandType = CommandType.Text;


using (SqlDataAdapter sda = new SqlDataAdapter(cmd1))
{
using (DataSet ds1 = new DataSet())
{


if (dr1.HasRows)
{




bool Empty = true;



foreach (DataGridViewRow row in dataGridView1.Rows)
{


for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
while (dr1.Read())
{


Empty = true;
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{



if (dataGridView1.Rows[i].Cells[1].Value != null && dataGridView1.Rows[i].Cells[1].Value.ToString() != "")
{
Empty = false;
break;
}
}



if (Empty)
{

row.Cells[1].Value = dr1.GetString(19);
row.Cells[1].Value = dr1.GetString(21);


}



}
}

}

dr1.Close();
con1.Close();
sda.Fill(ds1);




}
}
}
}
}


dataGridView1.Focus();
}

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