Hello,
i use the "Mutiselect drop down list column" from http://www.telerik.com/support/kb/winforms/gridview/details/mutiselect-drop-down-list-column-in-radgridview
I'm stuck in the implementation of a filter function (Filter must work in combine with other Columns). I found part of codes for custom filter functions and tried to combine them
The basic filter function works already:
So i can filter in custom column "Name" (MultiSelectDropdownColumn) and also in Column2 "Test" (TextboxColumn). good so far
After i filtered something in Column "Test" followed by clear this filter, i try to filter in custom column "Name" again but this time the filter don't work (all Rows will hidden or only one matching row will shown).
Does anyone have any idea where the fault lies?
i use the "Mutiselect drop down list column" from http://www.telerik.com/support/kb/winforms/gridview/details/mutiselect-drop-down-list-column-in-radgridview
I'm stuck in the implementation of a filter function (Filter must work in combine with other Columns). I found part of codes for custom filter functions and tried to combine them
The basic filter function works already:
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
Telerik.WinControls.UI;
using
Telerik.WinControls;
using
Telerik.WinControls.Data;
using
System.Diagnostics;
namespace
_547099
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
DataTable t =
new
DataTable();
t.Columns.Add(
"ID"
,
typeof
(
int
));
t.Columns.Add(
"Name"
,
typeof
(
string
));
t.Rows.Add(1,
"one"
);
t.Rows.Add(2,
"two"
);
t.Rows.Add(3,
"three"
);
t.Rows.Add(4,
"four"
);
t.Rows.Add(5,
"five"
);
t.Rows.Add(6,
"six"
);
t.Rows.Add(7,
"seven"
);
t.Rows.Add(8,
"eight"
);
t.Rows.Add(9,
"nine"
);
t.Rows.Add(10,
"ten"
);
CustomColumn col =
new
CustomColumn(
"MutiSelect column"
);
col.Name =
"Name"
;
col.DataSource = t;
col.DisplayMember =
"Name"
;
col.ValueMember =
"ID"
;
FilterDescriptor descriptor =
new
FilterDescriptor(
"Name"
, FilterOperator.Contains, 0);
//col.AllowFiltering = false;
radGridView1.Columns.Add(col);
GridViewTextBoxColumn col2 =
new
GridViewTextBoxColumn();
col2.Name =
"Test"
;
radGridView1.Columns.Add(col2);
radGridView1.Rows.Add(
new
object
[] {
new
int
[] { 9, 6, 10 },
"ab"
});
radGridView1.Rows.Add(
new
object
[] {
new
int
[] { 5, 1, 3 },
"abcd"
});
radGridView1.Rows.Add(
new
object
[] {
new
int
[] { 8, 7, 1 },
"ef"
});
radGridView1.Rows.Add(
new
object
[] {
new
int
[] { 4, 2, 1 },
"fgh"
});
this
.radGridView1.EnableFiltering =
true
;
this
.radGridView1.ShowHeaderCellButtons =
true
;
this
.radGridView1.EnableCustomFiltering =
true
;
this
.radGridView1.CustomFiltering +=
new
GridViewCustomFilteringEventHandler(radGridView1_CustomFiltering);
this
.radGridView1.CellEndEdit +=
new
GridViewCellEventHandler(radGridView1_CellEndEdit);
this
.radGridView1.CellValidating +=
new
CellValidatingEventHandler(radGridView1_CellValidating);
this
.radGridView1.FilterExpressionChanged += radGridView1_FilterExpressionChanged;
}
void
radGridView1_FilterExpressionChanged(
object
sender, FilterExpressionChangedEventArgs e)
{
Debug.WriteLine(
"Filter geändert: "
+ e.FilterExpression);
}
void
radGridView1_CellValidating(
object
sender, CellValidatingEventArgs e)
{
if
(radGridView1.ActiveEditor ==
null
||!( e.Row
is
GridViewFilteringRowInfo))
return
;
if
(e.Column.GetDefaultEditorType() ==
typeof
(CustomDropDownListEditor))
{
filterValues.Clear();
foreach
(CustomListDataItem item
in
((CustomEditorElement)(((CustomDropDownListEditor)(
this
.radGridView1.ActiveEditor)).EditorElement)).Items)
{
if
(item.Selected)
{
filterValues.Add((
int
)item.Value);
}
}
}
}
List<
int
> filterValues =
new
List<
int
>();
void
radGridView1_CellEndEdit(
object
sender, GridViewCellEventArgs e)
{
Debug.WriteLine(
"Refresh"
);
this
.radGridView1.MasterTemplate.Refresh();
}
private
void
radGridView1_CustomFiltering(
object
sender, GridViewCustomFilteringEventArgs e)
{
if
(filterValues.Count == 0)
{
Debug.WriteLine(
"FilterVal 0"
);
int
fdi = radGridView1.FilterDescriptors.IndexOf(
"Name"
);
if
(fdi != -1)
{
radGridView1.FilterDescriptors.RemoveAt(fdi);
}
}
if
(radGridView1.FilterDescriptors.Count == 0)
{
return
;
}
if
(filterValues.Count > 0)
{
bool
shouldVisible =
false
;
foreach
(
int
cellValue
in
((
int
[])e.Row.Cells[
"Name"
].Value))
{
foreach
(
int
j
in
filterValues)
{
if
(cellValue == j)
{
shouldVisible =
true
;
break
;
}
}
}
e.Visible = shouldVisible;
}
if
(e.Visible) e.Handled =
false
;
}
}
}
So i can filter in custom column "Name" (MultiSelectDropdownColumn) and also in Column2 "Test" (TextboxColumn). good so far
After i filtered something in Column "Test" followed by clear this filter, i try to filter in custom column "Name" again but this time the filter don't work (all Rows will hidden or only one matching row will shown).
Does anyone have any idea where the fault lies?