比较vb.net中的网格行 [英] Compare grid rows in vb.net

查看:110
本文介绍了比较vb.net中的网格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较gridrows。如果网格行1和2相等,它想要从网格中删除

解决方案

你的意思是删除重复行。



 对于 intX 正如 整数 =  0   DataGridView1.Rows.Count  -   2  
对于 intY 作为 整数 = intX + 1 DataGridView1.Rows.Count - 2
If DataGridView1.Rows( intX)。细胞( 2 )。Value = DataGridView1.Rows(intY).Cells( 2 )。值然后
DataGridView1.Rows.RemoveAt(intY)
结束 如果
下一步
下一步





了解更多详情查看此链接



从网格视图中消除重复值 [ ^ ]



http://csharpdotnetfreak.blogspot.com/2011/12/remove-duplicate-rows-datatable。 html [ ^


使用此功能。我想,你不应该删除行,你的意思是显示一条记录,如果下面的一条是相同的。此函数用于合并行。只需将gridview作为参数传递给此函数。

公共共享子MergeRows(gridView As GridView)
for rowIndex As Integer = gridView.Rows.Count - 2 To 0 步骤-1
Dim row As GridViewRow = gridView.Rows(rowIndex)
Dim previousRow As GridViewRow = gridView.Rows(rowIndex + 1

for i As Integer = 0 to row.Cells.Count - 4
如果是row.Cells(i)。 Text = previousRow.Cells(i).Text然后
row.Cells(i).RowSpan = If(previousRow.Cells(i).RowSpan < 2 2 ,previousRow.Cells(i).RowSpan + 1
previousRow.Cells(i).Visible = False
End if
Next
Next
End Sub



问候..:笑:

i want to compare the gridrows.if the grid rows 1 and 2 are equal it want to remove from the grid

解决方案

Do you mean Delete the Duplicate row.

For intX As Integer = 0 To DataGridView1.Rows.Count - 2
          For intY As Integer = intX + 1 To DataGridView1.Rows.Count - 2
              If DataGridView1.Rows(intX ).Cells(2).Value = DataGridView1.Rows(intY ).Cells(2).Value Then
                  DataGridView1.Rows.RemoveAt(intY )
              End If
          Next
      Next



for more details check this links

Eliminate Duplicate Values from the Grid View[^]

http://csharpdotnetfreak.blogspot.com/2011/12/remove-duplicate-rows-datatable.html[^]


Use this function. I think,you are not supposed to remove row,you mean to display one record if the below one is same. This function is used to merge rows.Just pass the gridview as parameter to this function.

Public Shared Sub MergeRows(gridView As GridView)
	For rowIndex As Integer = gridView.Rows.Count - 2 To 0 Step -1
		Dim row As GridViewRow = gridView.Rows(rowIndex)
		Dim previousRow As GridViewRow = gridView.Rows(rowIndex + 1)

		For i As Integer = 0 To row.Cells.Count - 4
			If row.Cells(i).Text = previousRow.Cells(i).Text Then
				row.Cells(i).RowSpan = If(previousRow.Cells(i).RowSpan < 2, 2, previousRow.Cells(i).RowSpan + 1)
				previousRow.Cells(i).Visible = False
			End If
		Next
	Next
End Sub


Regards..:laugh:


这篇关于比较vb.net中的网格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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