5 Answers, 1 is accepted
0
Hello Aled,
Thank you for writing.
If I understand correctly you have a checkbox outside the grid and you want to filter the grid using it. This can be achieved by adding/removing filter descriptor when the checkbox state is changed:
I hope this helps. Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Telerik by Progress
Thank you for writing.
If I understand correctly you have a checkbox outside the grid and you want to filter the grid using it. This can be achieved by adding/removing filter descriptor when the checkbox state is changed:
public
RadForm1()
{
InitializeComponent();
radGridView1.DataSource = GetTable();
radGridView1.EnableFiltering =
true
;
radCheckBox1.IsThreeState =
true
;
}
private
void
radCheckBox1_ToggleStateChanged(
object
sender, Telerik.WinControls.UI.StateChangedEventArgs args)
{
radGridView1.FilterDescriptors.Clear();
if
(args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
{
radGridView1.FilterDescriptors.Add(
"Bool"
, Telerik.WinControls.Data.FilterOperator.IsEqualTo,
true
);
}
else
if
(args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.Off)
{
radGridView1.FilterDescriptors.Add(
"Bool"
, Telerik.WinControls.Data.FilterOperator.IsNotEqualTo,
true
);
}
}
I hope this helps. Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Telerik by Progress
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
ALED
Top achievements
Rank 1
answered on 14 Jul 2016, 08:52 AM
Dear dimtar,
thank for reply,
No, in my case i have RadGridColumn which GridViewCheckBoxColumn and i want filter in radgrid by check or uncheck a checkbox in above column, its possible? if i check then will rebind / show data which contain checkbox checked, like that, its possible?
0
Hello Aled,
Thank you for writing back.
Using the checkbox in the filter cell should work out of the box (see attached video). Why do you want to rebind the grid at this point? Do you want to bind the grid to the filtered data or you just want to update the grid?
I am looking forward to your reply.
Regards,
Dimitar
Telerik by Progress
Thank you for writing back.
Using the checkbox in the filter cell should work out of the box (see attached video). Why do you want to rebind the grid at this point? Do you want to bind the grid to the filtered data or you just want to update the grid?
I am looking forward to your reply.
Regards,
Dimitar
Telerik by Progress
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
ALED
Top achievements
Rank 1
answered on 14 Jul 2016, 10:23 AM
Dear Dimitar,
thanks for writing back,
yes, i want rebind a grid, in this point reload datasource of a grid by Filtered CheckBoxColumn, Ex : in my Column Checkbox have 10 record, which 5 row is checked and 5 row not checked, when i changed filter with checkedt at the above column, then will reload datasource with 5 record only, in this point i used a filtered to query again on SQL query.
0
Hi Aled,
Thank you for writing.
Please note that changing the data source is recreating the entire grid. So to properly handle this as you desired you need to bypass the filtering functionality by adding a completely new check box to the cell. In addition, you need to keep the previous state and synchronize it every time the data source is reset (new cell is created when the data source is set.
Thank you for writing.
Please note that changing the data source is recreating the entire grid. So to properly handle this as you desired you need to bypass the filtering functionality by adding a completely new check box to the cell. In addition, you need to keep the previous state and synchronize it every time the data source is reset (new cell is created when the data source is set.
First, you can use the following custom cell class which adds new checkbox:
public
delegate
void
MyEventHandler(
object
source, StateChangedEventArgs e);
class
MyFiltercell : GridFilterCheckBoxCellElement
{
public
MyFiltercell(GridViewDataColumn column, GridRowElement row) :
base
(column, row)
{
}
RadCheckBoxElement checkBox =
new
RadCheckBoxElement();
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
var editor =
this
.Editor
as
RadCheckBoxEditor;
editor.EditorElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
this
.Children.Remove(editor.EditorElement);
this
.Children.Add(checkBox);
checkBox.IsThreeState =
true
;
checkBox.ShouldHandleMouseInput =
true
;
checkBox.NotifyParentOnMouseInput =
false
;
checkBox.ToggleStateChanged += CheckBox_ToggleStateChanged;
}
public
event
MyEventHandler OnToggle;
public
void
SyncState(Telerik.WinControls.Enumerations.ToggleState state)
{
checkBox.ToggleStateChanged -= CheckBox_ToggleStateChanged;
checkBox.ToggleState = state;
checkBox.ToggleStateChanged += CheckBox_ToggleStateChanged;
}
private
void
CheckBox_ToggleStateChanged(
object
sender, StateChangedEventArgs args)
{
if
(OnToggle !=
null
)
{
OnToggle(
this
, args);
}
}
protected
override
SizeF ArrangeOverride(SizeF finalSize)
{
var result =
base
.ArrangeOverride(finalSize);
checkBox.Arrange(
new
RectangleF(finalSize.Width / 2 - checkBox.DesiredSize.Width, 0, finalSize.Width, finalSize.Height));
return
result;
}
}
Then you can change the default cell and changed the data source:
I have attached a small sample project that shows this as well.
I hope this will be useful.
Telerik.WinControls.Enumerations.ToggleState oldState = Telerik.WinControls.Enumerations.ToggleState.Indeterminate;
private
void
Cell_OnToggle(
object
source, StateChangedEventArgs e)
{
var grid = radGridView1;
oldState = e.ToggleState;
if
(e.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
{
var newdata = from i
in
data
where i.Checked ==
true
select i;
grid.DataSource = newdata.ToList();
}
else
if
(e.ToggleState == Telerik.WinControls.Enumerations.ToggleState.Off)
{
var newdata = from i
in
data
where i.Checked ==
false
select i;
grid.DataSource = newdata.ToList();
}
else
{
grid.DataSource = data;
}
}
I have attached a small sample project that shows this as well.
I hope this will be useful.
Regards,
Dimitar
Telerik by Progress
Dimitar
Telerik by Progress
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.