Filtering when using DataGridView

S

Satya

Hi,
I am using a DataGridView to display a large amount of data and so
need to use filters for displaying certain data. For this I want to
provide a textbox for each column of the DataGridView so that the user
can type in any text and use that text as the filter. I would like to
have this textbox row as the first row of the DataGridView just below
the Header.

I saw someone asking this question one year back but there was no
solution suggested then.

Is anyone able to do this now? If so how?

thanks for your help,
Satya.
 
V

Vijay

Satya.. I am not sure if using the DataGrid row to do the search is such a
good idea.. but if you have UI requirements.. you can build a UI in such a
way that a row is being used... i.e more like a row of textboxes aligned on
top of the grid columns.. and you could keep them close enough to look as
grid columns.. , your life becomes easier... If I may know why are stuck on
the idea of using a datagrid row?

VJ
 
S

Satya

Hi Vijay,
I need the textboxes to appear below the header of the DataGridView
so that the user knows which textbox acts as a filter for which column
of the datagrid. Also, the columns of the DataGridView are configured
via an xml config file, so it is difficult to use textboxes. Also when
the user changes the order of the columns or resizes the columns of the
datagrid it is difficult to do the same with the textboxes.

Hope this clears up my problem. If not please let me know.

thanks,
Satya.
 
V

Vijay

Ok I do understand your case. I am not sure you can do with What windows
offers.. , you could try inheriting and overriding the Grid or the
GridTexboxcolumn to our own objects and work with the grid in the un-bound
mode, and add the rows manually... I have never done something like this...
but I can give a few links that might help you get started in manually
overrides and customizing grid and the grid columns, how to work in un-bound
mode... You could check the below..

http://www.syncfusion.com/faq/windowsforms/default.aspx

www.codeproject.com

Syncfusion also has variety of controls you can use.. try them out.. We use
Syncfusionn for our UI controls, pretty good so far.. We have not used much
of their Grid controls.. so I can't give much insight into that.

Sorry was not able to help you much...
Vijay
 
I

Ian Semmel

What you could maybe do is drop the datagridview and use ListView instead and
incorporate your filters into the ColumnHeader class
 
M

Mike Blake-Knox

Satya said:
I am using a DataGridView to display a large amount of data and so
need to use filters for displaying certain data. For this I want to
provide a textbox for each column of the DataGridView so that the user
can type in any text and use that text as the filter. I would like to
have this textbox row as the first row of the DataGridView just below
the Header.

I had the same need a while ago. I decided to add "Filter" column to my
DataTable. This column is intended to determine whether or not each row
is filtered. I then insert an empty row into the dataset and freeze it so
it's always onscreen.

In the CellValidated event for the DataGridView, I look to see if the
modified cell is in the filter row. If so, I generate a filter
expression that ands filter expressions (using the contents of each cell
in row zero as an operand for the "LIKE" opeerator). I then assign the
string with the expression to the bindingSource's Filter property.

Hope this helps

Mike
 
I

Ian Semmel

Actually, I was thinking more in MFC terms. On further investigation, ListView
seems severely nobbled in C#
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top