如何在datagrid中查找行的位置 [英] How to find a position of a row in datagrid

查看:74
本文介绍了如何在datagrid中查找行的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想根据传递的值从datagrid删除一行,因为那一号我需要找到所有值都在哪一行匹配.为此,我必须找到一行的位置.下面是我要编写的代码.

Hi Everyone,

I want to delete a row from datagrid according to the passed values, for that 1st i need to find at which row all values are matching. For this I have to find the position of a row.Below is the code I am trying to write.

dbcheck = "select * from qpoo where pono=''" & txtpono.Text & "'' and itemcode=''" & ComboBox1.SelectedItem & "'' and serialno=''" & txtserialno.Text & "''"
     Dim da As New SqlCeDataAdapter
     Dim ds As New DataSet
     da = New SqlCeDataAdapter(dbcheck, cn)
     da.Fill(ds, "qpoo")
     If ds.Tables("qpoo").Rows.Count = 0 Then
         MsgBox("Scanned item is not present")
         txtserialno.Text = ""
     Else
         dr(0) = txtpono.Text
         dr(1) = ComboBox1.SelectedItem
         dr(2) = txtserialno.Text
         Table1.Rows.Remove(dr)
     End If



任何帮助表示感谢.

提前谢谢.

[edit]添加了代码块-OriginalGriff [/edit]



Any help is kindly appreciated.

Thanks in advance.

[edit]Code block added - OriginalGriff[/edit]

推荐答案

您好,您可以使用基础数据源查找一些值,而不是在UI元素中进行搜索.要搜索您的值,可以在数据表中使用 Filter expressions,也可以在 DataRow 集合上使用 Find 方法.这是一个示例,如何在数据表上使用 select 方法进行查找

Hi to find some value use your underlying data source than searching in a UI element. To search your value you can use Filter expressions in your data table or else the Find method on the DataRow collections. Here is an example how to find using the select method on the data table

DataRow[] rows=dt.Select("ProductName='Product1'");
foreach(DataRow row in rows)
{
    dt.Rows.Remove(row);
}



(我希望这个简单的代码片段对您来说转换为vb.net并不困难).关键只是选择方法.

其中dt是指数据表,将过滤后的表绑定到数据网格.如果要从数据库中删除这些行,请从过滤的行中获取ID,并构造删除查询.

更好的方法是创建一个新的DataView并使用其RowFilter(其语法与此选择方法相同)并将dataview绑定到网格.因此,您的原始数据表不受影响.选择是你的.



(I hope this simple code snippet is not difficult for you to convert to vb.net). The key is just the select method.

where dt refers to a data table.Bind the filtered table to the data grid. If you want to remove those rows from the database then get the ids from the filtered rows and construct the delete query.

Even better way create a new DataView and use its RowFilter which has same syntax as this select method and bind the dataview to the grid. So your original datatable is unaffected. Choice is yours.


这篇关于如何在datagrid中查找行的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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