datagrid的頁內尋找函數

來源:互聯網
上載者:User
datagrid 在自己學著開發的過程中,寫了一些可重用的代碼,願與大家分享一下.
因為datagrid沒有像delphi中的網格的網格內數據的尋找功能,於是自己動手寫了一個:




--------------------------------------------------------------------------------
'
Public Function findto(ByVal mDataGrid As DataGrid, ByVal nowindex As Integer, ByVal maxindex As Integer, ByVal caps As Boolean, ByVal updown As Boolean, ByVal mFieldName As Integer, ByVal mFieldValue As String) As Integer

Dim rowIndex As Integer = -1
Dim regstring As String
regstring = mFieldValue.Replace("\", "\\")
Dim dgrow As Integer
Try
Dim rx As System.Text.RegularExpressions.Regex
If caps Then
rx = New System.Text.RegularExpressions.Regex(regstring, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
Else
rx = New System.Text.RegularExpressions.Regex(regstring)
End If
If updown Then
For dgrow = nowindex - 1 To 0 Step -1
If rx.IsMatch(mDataGrid.Item(dgrow, mFieldName).ToString) Then
rowIndex = dgrow
If rowIndex <= nowindex Then
mDataGrid.CurrentRowIndex = rowIndex
Else
rowIndex = -1
End If
Exit For
End If
Next
Else
For dgrow = nowindex + 1 To maxindex
If rx.IsMatch(mDataGrid.Item(dgrow, mFieldName).ToString) Then
rowIndex = dgrow
If rowIndex >= nowindex Then
mDataGrid.CurrentRowIndex = rowIndex
Else
rowIndex = -1
End If
Exit For
End If
Next
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Return rowIndex

End Function

'使用時
Dim findindex As Integer '找到的行
Dim currow As Integer
Dim curcol As Integer
curcol = sFieldName.SelectedIndex
If curcol = 0 Then Exit Sub
currow = DataGrid1.CurrentRowIndex '
DataGrid1.UnSelect(currow)
'功能說明: (選中該行)
'findto(網格的名稱,當前行號,數據記錄數,區分大小寫,向上or向下尋找方向,列號,查詢值)
findindex = findto(DataGrid1, currow, ds_rec.Tables("rec").Rows.Count - 1, cap, searup, curcol, sFieldValue.Text.ToString)
If findindex <> -1 Then
DataGrid1.Select(findindex)
Else
MsgBox("沒有找到匹配的項目!", MsgBoxStyle.Information, "尋找結果")
DataGrid1.CurrentRowIndex = currow
DataGrid1.Select(currow)
End If




相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。