Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have datagridview in that textboxes and comboxes there.If i enter values into the first textbox.and then click enter or tab new empty row will be come top of the datagridview.
How to do that i Have found some codes but in which event i need to write.Please anybody could help me on this.Thanks in advance.

What I have tried:

C#
   dgvwChqs.Rows.Insert(0, new string[] {
null, null,null,null,null });
Posted
Updated 15-May-17 4:03am

1 solution

The even you probably want to use is TextBox1_Validated

That event means that any validation that needs to occur on the TextBox has been completed and the contents of the TextBox are valid.

You absolutely do not want to use TextBox1_TextChanged because you will end up with a new row for every keystroke in TextBox1!

[EDIT]
The above solution assumed that you had a textbox separate to the DataGridView and entering data into it would prompt a new row being added to the DGV.

OP has now indicated that they are entering data into the first textbox column of the DGV itself and want to add a row at that point.

As far as I can determine you cannot do this as the act of editing a row temporarily prevents new rows being added. There is a list of the events that are affected on this link DataGridViewRowCollection.Add Method (System.Windows.Forms)[^]

An alternative is to have an "input area" for the DGV - you could potentially position a textbox over the DGV and then use the technique I originally suggested.
 
Share this answer
 
v2
Comments
Member 13153537 15-May-17 10:08am    
In datagridview textbox has Textbox1_Valiadated event option not available.
CHill60 15-May-17 10:34am    
When you said you were entering data into the first textbox I did not realise that you meant you were entering data into the first column on the datagridview. How can you enter data into a row that doesn't already exist?
Nevertheless, I will update my solution with the appropriate event
Member 13153537 15-May-17 10:46am    
ok Thanks.

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