Articles in this section

How to select a Row by Cell Value in WinForms DataGrid?

In a WinForms DataGrid (SfDataGrid), a row can be selected based on a specific cell value. A TextBoxhas been implemented to allow users to enter the desired cell value. If the entered value matches any value within the DataGrid columns, the corresponding row is retrieved and set as the SelectedItem.

private void SelectRow(object sender, EventArgs e)
{
    // Retrive the data based on entered cell value.
    var rowData = orderInfoCollection.Orders.FirstOrDefault(data => 
                  data.OrderID.ToString().ToLower() == textBox1.Text.ToLower() ||
                  data.CustomerID.ToString().ToLower() == textBox1.Text.ToLower() ||
                  data.CustomerName.ToString().ToLower() == textBox1.Text.ToLower() ||
                  data.ShipCity.ToString().ToLower() == textBox1.Text.ToLower() ||
                  data.Country.ToString().ToLower() == textBox1.Text.ToLower());

    // Select the retrived data
    this.sfDataGrid1.SelectedItem = rowData;
}

SelectRowByCellValue.gif

Take a moment to peruse the WinForms DataGrid - Selection documentation, to learn more about DataGrid Selections with examples.

View sample in GitHub

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied