programmatically select a row based on gridview values

后端 未结 1 1853
天命终不由人
天命终不由人 2021-01-25 18:05

What I have

I have a DataGridView with 3 columns (metric_key, metric_name, metric_value).

There are for example, 6 ROWS in this table (6 different metrics), ad

1条回答
  •  无人共我
    2021-01-25 19:01

    There isn't a built in way to do this. But you can define an extension method on DataGridView to accomplish this.

     _
    Function FindValue(ByRef dgv As DataGridView, ByVal metric_key As Object) As DataGridViewRow
        For Each row As DataGridViewRow In dgv.Rows
            If row.Cells.Item("metric_value").Value = metric_key Then
                Return row
            End If
        Next
        Return Nothing
    End Function
    

    So if you wanted to get the row where the metric_value is 1, you could use

    dataGridView1.FindValue(1)
    

    0 讨论(0)
提交回复
热议问题