如何在不使用C#windows应用程序中的按钮的情况下添加datagridview的新行顶部 [英] How to add new row top of the datagridview without using button in C# windows application

查看:59
本文介绍了如何在不使用C#windows应用程序中的按钮的情况下添加datagridview的新行顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那里的文本框和combox中有datagridview。如果我在第一个文本框中输入值,然后单击enter或tab新的空行将成为datagridview的顶部。

怎么办我找到了一些代码,但我需要写一些代码。请有人帮我这个。谢谢。



我试过的:



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:

   dgvwChqs.Rows.Insert(0, new string[] {
null, null,null,null,null });

推荐答案

你可能想要使用的是 TextBox1_Validated



该事件意味着需要在TextBox上进行的任何验证都已完成,TextBox的内容有效。



你绝对想要使用 TextBox1_TextChanged ,因为每次击键都会得到一个新行在TextBox1中!





上述解决方案假设您有一个与DataGridView分开的文本框并输入数据进入它会提示新的行被添加到DGV。



OP现在已经表明他们正在将数据输入到DGV本身的第一个文本框列中并希望在那一点添加一行。



据我所知,你不能这样做,因为编辑行的行为会暂时阻止添加新行。有一个受此链接影响的事件列表 DataGridViewRowCollection.Add Method(System.Windows.Forms) [ ^ ]



另一种方法是为DGV设置一个输入区域 - 您可以将文本框放在DGV上,然后使用我最初建议的技术。
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!


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.


这篇关于如何在不使用C#windows应用程序中的按钮的情况下添加datagridview的新行顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆