从datagridview中删除当前行 [英] Remove the current row from datagridview

查看:236
本文介绍了从datagridview中删除当前行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..



我想删除数据网格中的当前行,我该怎么做呢。我想在单元格输入事件中写这个。

我在这里做的是在数据网格中的单元格输入事件我正在检查天气输入的值已经存在于数据库中。如果是这样我将清除输入的值并想要删除该行。在这里我不知道如何删除这一行。



谢谢...

hi..

i want to remove the current row in the data grid how can i do this. and i wants to write this in cell enter event.
what i am doing here is in cell enter event in the data grid i am checking weather the the entered value is already there in the database. if it so i am clearing that entered value and wants to remove that row. here i don't know how to remove this row.

thank you...

推荐答案

假设使用的Datagrid的名称是dgvGrid

现在要删除当前选定的行,请使用以下代码



dgvGrid.Rows.RemoveAt (dgvGrid.CurrentRow.Index);



||你可以通过编写要删除的行索引来删除任何索引处的行



如删除索引'i'代码的行如下: -



dgvGrid.Rows.RemoveAt(i); < br $> b $ b
$ b $猜猜这有帮助..
Supposing the name of the Datagrid used is dgvGrid
Now to remove the currently selected row please use the following code

dgvGrid.Rows.RemoveAt(dgvGrid.CurrentRow.Index);

||ly you cam remove row at any index by writing the row index you want to remove

such as removing row at index 'i' code is as follows:-

dgvGrid.Rows.RemoveAt(i);

i guess this helps..


你可以使用Row验证事件。



检入数据库是否有重复。现在如果不希望用户输入该垃圾值,请转e.Cancel = True它将不允许用户进入下一行。



它不会删除行但是它不允许下一个。



private void dataGridView1_RowValidating(object sender,DataGridViewCellCancelEventArgs e)

{

if(dataGridView1.Rows [e.RowIndex] .Cells [name]。Value.ToString()==test)

{

MessageBox。显示(无法输入);

e.Cancel = true;

}



}



只需测试一下这段代码。

希望它适用于你。
You can use Row validating event.

Check in database for duplication. Now if dont want user to enter that garbage value, Turn e.Cancel = True it will not allow user to go for next row.

It will not remove row but it will not allow to for next one.

private void dataGridView1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
if (dataGridView1.Rows[e.RowIndex].Cells["name"].Value.ToString() == "test")
{
MessageBox.Show("can't enter");
e.Cancel = true;
}

}

Just test this code.
Hope it will work for u.


hi .. 。



在这里,我想在单元格输入事件中编写此代码。但是当我在那里写它时会给出一个错误说:

在这个事件处理程序中无法执行操作。



所以我现在必须做。



(我真的不知道我怎么能回答你给出的答案。我希望这是我应该怎么做的。)



再次感谢..
hi...

here, i wanted to write this code in cell enter event. but when i write it there its giving an error saying:
"Operation cannot be performed in this event handler."

so what i have to do now.

(i really don't know how can i reply for the answered you have given. i hope this is the way how i should do.)

thanks again..


这篇关于从datagridview中删除当前行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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