Is it possible to search for Values in DataGridview with Linq?

Hi,

is it possible to search for cells values in Cells of a DataGridView using Linq. My target is to search values in a DataGridView without loops.

[150 byte] By [rgerbig] at [2008-2-6]
# 1
Linq can search through any class that implements/returns IEnumerable<T>. The DataGridView class as such does not implement this interface so you cannot direct search the class reference.

You would be able to Search through its data source but not the DataGridView class itself.

Regards,
Saurabh Nandu
www.MasterCSharp.com

SaurabhNandu at 2007-9-9 > top of Msdn Tech,Visual Studio Orcas,LINQ Project General...
# 2
Hi,

what about searching the arrays of the datagridview? will there be any way?

rgerbig at 2007-9-9 > top of Msdn Tech,Visual Studio Orcas,LINQ Project General...
# 3
You'd need to create some sort of adapter. An extension method, for example, could add a method to present the visible rows of the DataGridView as an IEnumerable<RowType> or the like, which could then be consumed as "from row in dataGridView.GetVisibleRows<RowType>()".

RowType could take a dataGridView row and reference it internally, its properties accessing it:

class RowType
{
private readonly DataGridViewRow _row;

public RowType(DataGridViewRow row)
{
this._row = row;
}

public string Name { get { ... fetch the Name data from the row ... } }
}

This should be able to give you access to the data grid view via LINQ, and still maintain at least an illusion of type safety.

You could also use this as a means to petition for a strongly typed GridView<RowType> :)

KeithFarmer at 2007-9-9 > top of Msdn Tech,Visual Studio Orcas,LINQ Project General...

Visual Studio Orcas

Site Classified