I would like to go to the database every time a user inputs a filter and then clicks on the filter button.
So 2 things are different here.
Thanks
So 2 things are different here.
- Filter does not get applied as user types in the filter, but only when user clicks on the filter button for that column.
- When user clicks on the filter button, then a new result set is returned from database based on filter condition. The results of this filter query will re-bind the database.
Thanks
7 Answers, 1 is accepted
0
Richard Slade
Top achievements
Rank 2
answered on 12 Oct 2010, 03:29 PM
Hi,
Emanuel helped someone to filter onLeave of the filter with this excellent solution. See this forum post
http://www.telerik.com/community/forums/winforms/gridview/filtering-question.aspx
You can adapt this to go back to the database and rebind the data based on the filter.
Hope that helps
Richard
Emanuel helped someone to filter onLeave of the filter with this excellent solution. See this forum post
http://www.telerik.com/community/forums/winforms/gridview/filtering-question.aspx
You can adapt this to go back to the database and rebind the data based on the filter.
Hope that helps
Richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 12 Oct 2010, 04:58 PM
Hello Sunil, Richard
Richard is right, for the first part you can use my answer from there, and thank you very much Richard for mentioning me.
The second part is the difficult one, because you are in a Cell event, you cannot change the data source for the grid without it crashing, so the first thing that came to mind is to use a Timer, and get the data on Tick, and set it as a DataSource to the grid there.
If you decide to go with this version, please be careful to either use a System.Windows.Forms.Timer because this one is running on the MainThread or use a synchronization context, or invoke using delegates to avoid CrossThreadOperation Exceptions.
The example should be something like this:
Hope this helps, if you have any other questions or comments, please let me know,
*Update - sorry for the first sentence in the original message, i forgot to clean it up
Best Regards,
Emanuel Varga
Richard is right, for the first part you can use my answer from there, and thank you very much Richard for mentioning me.
The second part is the difficult one, because you are in a Cell event, you cannot change the data source for the grid without it crashing, so the first thing that came to mind is to use a Timer, and get the data on Tick, and set it as a DataSource to the grid there.
If you decide to go with this version, please be careful to either use a System.Windows.Forms.Timer because this one is running on the MainThread or use a synchronization context, or invoke using delegates to avoid CrossThreadOperation Exceptions.
The example should be something like this:
void
radGridView1_CellEndEdit(
object
sender, GridViewCellEventArgs e)
{
var filteringRow = e.Row
as
GridViewFilteringRowInfo;
if
(filteringRow !=
null
)
{
if
(lastFilterDescriptor !=
null
)
{
var propertyName = lastFilterDescriptor.PropertyName;
var filterOperator = lastFilterDescriptor.Operator;
var filterValue = lastFilterDescriptor.Value.ToString();
switch
(filterOperator)
{
case
FilterOperator.Contains:
ChangeDataSource(
true
, filterValue);
break
;
case
FilterOperator.NotContains:
ChangeDataSource(
false
, filterValue);
break
;
case
FilterOperator.EndsWith:
break
;
case
FilterOperator.IsContainedIn:
break
;
case
FilterOperator.IsEqualTo:
break
;
case
FilterOperator.IsGreaterThan:
break
;
case
FilterOperator.IsGreaterThanOrEqualTo:
break
;
case
FilterOperator.IsLessThan:
break
;
case
FilterOperator.IsLessThanOrEqualTo:
break
;
case
FilterOperator.IsLike:
break
;
case
FilterOperator.IsNotContainedIn:
break
;
case
FilterOperator.IsNotEqualTo:
break
;
case
FilterOperator.IsNotLike:
break
;
case
FilterOperator.IsNotNull:
break
;
case
FilterOperator.IsNull:
break
;
case
FilterOperator.None:
break
;
case
FilterOperator.StartsWith:
break
;
default
:
break
;
}
}
}
}
private
void
ChangeDataSource(
bool
containsString,
string
stringToContain)
{
radGridView1.EndEdit();
var timer =
new
System.Windows.Forms.Timer();
timer.Interval = 1;
timer.Tick +=
delegate
{
timer.Stop();
// if by any chance it takes more than 1ms you could make the timer thread wait while the grid finished validating
//while (radGridView1.IsInEditMode)
//{
// Thread.Sleep(20);
//}
// get data from DB based on these values
radGridView1.DataSource =
new
BuyersCollection(containsString, stringToContain);
};
timer.Start();
}
Hope this helps, if you have any other questions or comments, please let me know,
*Update - sorry for the first sentence in the original message, i forgot to clean it up
Best Regards,
Emanuel Varga
0
SUNIL
Top achievements
Rank 2
Iron
Iron
Iron
answered on 12 Oct 2010, 07:14 PM
Hi Emanuel,
Thanks for your answer.
My only problem is that I am using Q1 2008 SP1 version in my app.
So this code may not work for me.
Thanks
Sunil
Thanks for your answer.
My only problem is that I am using Q1 2008 SP1 version in my app.
So this code may not work for me.
Thanks
Sunil
0
Emanuel Varga
Top achievements
Rank 1
answered on 12 Oct 2010, 07:28 PM
Hello Sunil,
Best chances are you are right about that, if possible i would strongly suggest you update to the latest version, and the reasons for this are many.
I'm not even going to bring up the recent virtualization and strong performance boosts in the main controls section.
But there are also smaller reasons, like the fact that chances are slim to none that you will be find a lot of people with that version and who are willing to help. (I don't even think that the admins still have that version installed somewhere - but i might be wrong).
If you have any other questions i can help you with, please, do not hesitate to say so.
Best Regards,
Emanuel Varga
Best chances are you are right about that, if possible i would strongly suggest you update to the latest version, and the reasons for this are many.
I'm not even going to bring up the recent virtualization and strong performance boosts in the main controls section.
But there are also smaller reasons, like the fact that chances are slim to none that you will be find a lot of people with that version and who are willing to help. (I don't even think that the admins still have that version installed somewhere - but i might be wrong).
If you have any other questions i can help you with, please, do not hesitate to say so.
Best Regards,
Emanuel Varga
0
Hi Sunil,
When posting in our Forums please share your product version, especially if it is not the latest version. This information is vital for everyone who would like to assist you.
We will greatly appreciate your assistance in this.
Regards,
Vassil
the Telerik team
When posting in our Forums please share your product version, especially if it is not the latest version. This information is vital for everyone who would like to assist you.
We will greatly appreciate your assistance in this.
Regards,
Vassil
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Ramin Naderi
Top achievements
Rank 1
answered on 25 Jun 2013, 11:17 AM
Hi
I have some code like this:
Every time i type a word in filter row, my program work decussate.
In other words, bellow code does not work correctly:
Excuse my bad english.
I have some code like this:
private Telerik.WinControls.Data.FilterDescriptor lastFilterDescriptor;
private void GridControl_FilterChanging(object sender, GridViewCollectionChangingEventArgs e)
{
if (GridControl.IsInEditMode)
{
e.Cancel = true;
}
lastFilterDescriptor = ((Telerik.WinControls.Data.FilterDescriptor)e.NewItems[0]);
}
private void GridControl_CellEndEdit(object sender, GridViewCellEventArgs e)
{
var filteringRow = e.Row as GridViewFilteringRowInfo;
if (filteringRow != null)
{
GridControl.FilterDescriptors.Remove(e.Column.Name);
if (lastFilterDescriptor != null && lastFilterDescriptor.PropertyName == e.Column.Name)
{
_timer.Interval = 10;
_timer.Tick += delegate
{
_timer.Stop();
GridControl.DataSource=GetDataSource();
GridControl.FilterDescriptors.Add(lastFilterDescriptor);
};
_timer.Start();
}
}
}
In other words, bellow code does not work correctly:
private void GridControl_CellEndEdit(object sender, GridViewCellEventArgs e)
{
var filteringRow = e.Row as GridViewFilteringRowInfo;
if (filteringRow != null)
{
GridControl.FilterDescriptors.Remove(e.Column.Name);
if (lastFilterDescriptor != null && lastFilterDescriptor.PropertyName == e.Column.Name)
{
GridControl.FilterDescriptors.Add(lastFilterDescriptor);
}
}
}
0
Hello Ramin,
Thank you for writing.
I tested the code you have provided and everything worked correctly. I just copy-pasted your code and set a data source. I tested the code with our latest version which currently is Q2 2013. If you are using a different version I would kindly ask you to post the version of the controls you are using so I can test the code with it.
Looking forward to your reply.
Regards,
Ivan Petrov
Telerik
Thank you for writing.
I tested the code you have provided and everything worked correctly. I just copy-pasted your code and set a data source. I tested the code with our latest version which currently is Q2 2013. If you are using a different version I would kindly ask you to post the version of the controls you are using so I can test the code with it.
Looking forward to your reply.
Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>