GridFilterBar - Selecting an item in the ListBox

Hi!

How can I select an item in a GridFilterBar's ListBox programmatically?

listBox.SelectedItem, listBox.SelectedIndex and listBox.SelectedValue don't work.

protected override void OnCreatingColumnHeader(GridFilterBarCreatingColumnHeaderEventArgs e) {
GridCurrentCell cc = _grid.CurrentCell;

if(cc.RowIndex == 1 && cc.ColIndex > 0) {
GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
if(cr == null) {
return;
}
ListBox lb = cr.ListBoxPart;
if(lb == null) {
return;
}


ArrayList al = ActiveFilters[e.ColName] as ArrayList;
if(al != null) {
if(al.Count == 1 && !e.ColName.Equals(CommonGlobals.FLD_STATUS)) {
DataRowView selectedItem = null;
foreach(DataRowView drv in lb.Items) {
if(drv[0].ToString().Equals(al[0].ToString())) {
selectedItem = drv;
}
}
if(selectedItem != null) {
lb.Items.Add(selectedItem);
lb.SelectedItem = selectedItem;
}
}
}
}

// base.OnCreatingColumnHeader (e);
}

Thanks for your help!!
Dan

1 Reply

AD Administrator Syncfusion Team October 18, 2006 04:17 PM UTC

Hi Dan,

If you want to programmatically apply filter, you can set the FilterBar.RowFilter property. Try the code below to do this.

// get the columnindex on which filter must be applied
int col = this.gridDataBoundGrid1.Binder.NameToColIndex("Column Name");

this.gridDataBoundGrid1.Model[1, col].Text = "value"; // filter value
filterBar.RowFilter = "[Column Name] = 'value'";

Let me know if this is not what you needed.
Thanks,
Rajagopal

Loader.
Up arrow icon