Click here to Skip to main content
15,568,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi...
I have one datagridview in my windows form. That is filling data from database based on selected value in the combo-box. For some selected item there is record in the database. for some there is no records. At that time i need to maintain a fixed size datagridview with no records filled in it(minimum 10 record). if the number of record is less than 10 then i need to fill it with null rows to achieve the count of 10. Is there any way to do this. If yes please help me.. i tried to add null value row to the data-source of grid-view. but it causing some problems while processing the grid-view values.
Posted
Comments
AshishChaudha 11-Oct-12 1:22am    
Could we see what you have tried so far??
ManjIndian 11-Oct-12 1:53am    
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con=new SqlConnection(@"Data Source=SA;Initial Catalog=bookStore;Integrated Security=True");
con.Open();
SqlCommand com = new SqlCommand("Select * from b", con);//("select title,author,genre from b",con);
SqlDataReader dr =com.ExecuteReader();
DataTable dt=new DataTable();
dt.Load(dr);
dataGridView1.DataSource = dt;
if (dataGridView1.Rows.Count < 20)
{
int r = 20 - dataGridView1.Rows.Count;
for (int i = 0; i < r; i++)
{
AddARow(dt);
}
}
dataGridView1.DefaultCellStyle.BackColor = Color.SkyBlue;
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.White;

}
private void AddARow(DataTable table)
{

DataRow newRow = table.NewRow();


table.Rows.Add(newRow);
}

1 solution

Hi,

After fetching the data from data base. Traverse the data for each combo selection and add if the count is less then 10 add more object into the list to reach count 10.
 
Share this answer
 
v2

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