Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to increase or decrease the no of rows in datagridview based on the value entered in the textbox in windows forms application using C#.
The no of Columns is fixed to 3.

My Requirement like a form filling which contains Three Columns like S.No, CompanyName,Location. Based on the Requirement i want to select no of rows and enter the values.
Posted
Comments
Arasappan 26-Aug-15 7:59am    
do u whant to show the top
M.Balakrishna 26-Aug-15 8:07am    
S. Based on the requriment want to increase the rows
Arasappan 26-Aug-15 8:23am    
set auto postback on text box
Arasappan 26-Aug-15 8:28am    
on textbox text changed
{
write the query


select top '"+value.TextBox+"' * from tbl_customerdetails
}
CHill60 26-Aug-15 9:31am    
Open to SQL Injection attacks. Use parameterised query instead

1 solution

If you want the user to enter the details then try something like
C#
private void textBox1_Validated(object sender, EventArgs e)
{
    dataGridView1.Rows.Clear();
    dataGridView1.AllowUserToAddRows = false;

    int numRows;
    if (int.TryParse(textBox1.Text, out numRows))
    {
        dataGridView1.Rows.Add(numRows);
    }
}
You will also need some validation to check that all the rows of the "form" have been "filled in" e.g. in the dataGridView1_Validating event
 
Share this answer
 

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