单击按钮后有条件删除(radgridview)
假设我在GridView中有2列:A列和B列B。
如果列B没有值,我想删除整个行。
此代码如果没有任何值,请检查B列B。接下来,如何根据从代码获得的值输入删除命令?
private void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRowInfo row in DGV1.Rows)
{
if (row.Cells[1].Value == null || Convert.ToString(row.Cells[1].Value) == string.Empty)
{
MessageBox.Show("Null value");
}
}
}
assume I have 2 columns in gridview : column A and column B.
I want to delete the whole row if Column B has no value.
this code checks column B if it doesn't have any value. next, how to enter the delete command based on the value obtained from the code ?
private void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRowInfo row in DGV1.Rows)
{
if (row.Cells[1].Value == null || Convert.ToString(row.Cells[1].Value) == string.Empty)
{
MessageBox.Show("Null value");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望我可以提供一些用于使用
radgridview
或实际上所有网格视图的技巧。首先,使用beginInvoke
避免阻止单击消息,该消息允许UI线程从单击处理程序返回(鼠标返回到UP位置,绘制了任何新按钮状态)。接下来,制作需要删除的一系列记录(或行)。如果您的视图绑定到
DataSource
使用system.linq
特别容易。然后只需从dataSource
中删除即可。此特定代码使用此
记录
类定义一行:如果您使用的是winforms
datagridview
它可以这样初始化:您的帖子是
telerik.wincontrols.ui.radgridview
,但初始化非常相似:希望这有助于您将自己想要的位置带到您想要的位置。
Hopefully I can offer a couple of tips for working with
RadGridView
or really most any grid view. First, useBeginInvoke
to avoid blocking the Click message which allows the UI thread to return from the click handler (mouse returns to the up position, any new button state is painted).Next make an array of records (or rows) that need to be removed. If your view is bound to a
DataSource
this is especially easy usingSystem.Linq
. Then simply remove fromDataSource
.This particular code defines a row with this
Record
class:If you were using a Winforms
DataGridView
it could initialize like this:Your post is for
Telerik.WinControls.UI.RadGridView
but the initialization is very similar:Hope this helps get you where you want to be.