我想隐藏数据行而不在c#或vb.net中将其删除。请帮我解决一下这个。 我想隐藏数据行而不在c#或vb.net中将其删除。
ResultSelection.Checked = False ' Checkbox
Dim Dt As DataTable
Dim dr as datarow
Private SBind As BindingSource = New BindingSource()
With Dt
.Columns.Add(" Name", GetType(String))
.Columns.Add("Age" , GetType(integer))
.Columns.Add("Marks" , GetType(integer))
dr(0) = ( "Mark",19,99)
dr(1) = ( "Rahul",20,35)
dr(2) = ( "Steve",19,50)
SBind.DataSource = Dt
DatargridView.DataSource = SBind
if ResultSelection.Checked = False then
"entire row dr(2) should not be visible
else
"entire data table should be visible along with dr(2)
end if
答案 0 :(得分:0)
您不能在DataTable
中隐藏行,但可以在DataView
中隐藏行。默认情况下,每个DataTable
在其DataView
属性中都有一个与其关联的DefaultView
。绑定DataTable
时,实际上是数据来自的DefaultView
。这样,您可以设置RowFilter
中的DataView
,以便隐藏不符合某些条件的行。例如,如果您有一个包含“男性”或“女性”的Sex
列,则可以隐藏所有“男性”行,如下所示:
myDataTable.DefaultView.RowFilter = "Sex = 'Female'"
绑定到DataTable
的任何控件都不会看到“男性”行,您也可以遍历DataView
代码以查看过滤后的数据。
如果要绑定,我建议在两者之间使用BindingSource
,在这种情况下,您可以用相同的方式设置其Filter
属性。