3 Answers, 1 is accepted
0
Hi Goran,
Thank you for writing.
RadGridView exposes a FilterChanging event which you can handle depending on your business logic. In order to disable the filtering while typing in the editor, you would need to keep track of the old and new filter values. The filter descriptor needs to be added just before the cell ends editing. Please check my code snippet below:
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
Thank you for writing.
RadGridView exposes a FilterChanging event which you can handle depending on your business logic. In order to disable the filtering while typing in the editor, you would need to keep track of the old and new filter values. The filter descriptor needs to be added just before the cell ends editing. Please check my code snippet below:
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
this
.radGridView1.DataSource =
this
.GetData();
this
.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this
.radGridView1.EnableFiltering =
true
;
this
.radGridView1.FilterChanging += radGridView1_FilterChanging;
this
.radGridView1.CellBeginEdit += radGridView1_CellBeginEdit;
this
.radGridView1.CellEndEdit += radGridView1_CellEndEdit;
}
private
void
radGridView1_CellEndEdit(
object
sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
if
(e.Row
is
GridViewFilteringRowInfo)
{
oldValue =
null
;
}
}
bool
shouldCancel;
private
void
radGridView1_CellBeginEdit(
object
sender, Telerik.WinControls.UI.GridViewCellCancelEventArgs e)
{
if
(e.Row
is
GridViewFilteringRowInfo)
{
((GridViewDataColumn)e.Column).FilterDescriptor =
null
;
}
}
object
oldValue;
private
void
radGridView1_FilterChanging(
object
sender, Telerik.WinControls.UI.GridViewCollectionChangingEventArgs e)
{
if
( oldValue != e.NewValue)
{
e.Cancel =
true
;
}
oldValue = e.NewValue;
}
private
DataTable GetData()
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Id"
,
typeof
(
int
));
dt.Columns.Add(
"Name"
,
typeof
(
string
));
dt.Columns.Add(
"Date"
,
typeof
(DateTime));
dt.Columns.Add(
"Bool"
,
typeof
(
bool
));
dt.Columns.Add(
"Description"
,
typeof
(
string
));
for
(
int
i = 0; i < 100; i++)
{
dt.Rows.Add(i,
"Name "
+ i, DateTime.Now.AddDays(i), i % 2 == 0,
"Description "
+ i);
}
return
dt;
}
}
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
goran
Top achievements
Rank 1
answered on 26 May 2016, 03:26 PM
I just want to change BeginEdit function not to clear filter when you enter cell.
So i wrote like this.
private
void
gridClients_CellBeginEdit(
object
sender, GridViewCellCancelEventArgs e)
{
if
(e.Row
is
GridViewFilteringRowInfo)
{
if
(
this
.gridClients.CurrentCell.Value !=
null
)
((GridViewDataColumn)e.Column).FilterDescriptor.Value =
this
.gridClients.CurrentCell.Value;
else
((GridViewDataColumn)e.Column).FilterDescriptor =
null
;
}
}
It works fine until i enter cell again and delete content of cell.
Then ((GridViewDataColumn)e.Column).FilterDescriptor became NULL and start crashing. When i try to set column FilterDescriptor again from code it wont accept changes ?
FilterDescriptor descriptor = CreateNewFilterDescriptor(
this
.gridPersons.CurrentCell.Value, (GridViewDataColumn)e.Column);
//dont work
((GridViewDataColumn)e.Column).FilterDescriptor = descriptor;
//dont work either
//this.gridPersons.FilterDescriptors.Add(descriptor);
0
Hello Goran,
Thank you for writing.
I am not able to observe the exception on my end. I have modified my project to suggest a slightly different approach and not omitting the existing filter when a cell is about to be edited.
I hope this helps. Please let me know if you need further assistance.
Regards,
Hristo Merdjanov
Telerik
Thank you for writing.
I am not able to observe the exception on my end. I have modified my project to suggest a slightly different approach and not omitting the existing filter when a cell is about to be edited.
I hope this helps. Please let me know if you need further assistance.
Regards,
Hristo Merdjanov
Telerik
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.