如何根据DevExpress
值选择GridView
TextBox
上的完整行?
我尝试了以下代码,但它无效:
Dim rowHandle As Integer = GridView1.LocateByDisplayText(0, colC_Id, txtSelect.Text)
If rowHandle <> DevExpress.XtraGrid.GridControl.InvalidRowHandle Then
Dim row As System.Data.DataRow = GridView1.GetDataRow(GridView1.FocusedRowHandle)
row(0) = txtSelect.EditValue
End If
答案 0 :(得分:2)
该代码未在GridControl中选择一行。它对GridColumn colC_Id中的文本框中输入的文本进行区分大小写搜索,如果找到匹配项,GridControl数据源的第二列(列索引1)中的文本将更新为输入的文本。当前选中的行。如果数据源中的该字段已添加到GridControl的GridColumn集合中,则更新后的值将反映在GridControl中。
以下是如何根据GridControl的数据源为DataTable的特定值选择GridControl中的行的示例:
Dim myDataTable As DataTable = DirectCast(GridControl1.DataSource, DataTable)
Dim sFieldName As String = colC_Id.FieldName
Dim sColumnName As String = colC_Id.Name
Dim myDataRows As DataRow() = myDataTable.Select(sFieldName & "='" & TextBox1.Text.Replace("'", "''") & "'")
If myDataRows.Length > 0 Then
Dim iDataSourceRowIndex As Int32 = myDataTable.IndexOf(myDataRows(0))
GridView1.FocusedRowHandle = GridView1.GetRowHandle(iDataSourceRowIndex)
Else
MessageBox.Show("The text '" & TextBox1.Text & "' was not found in column '" & sColumnName &"'")
End If