.Net Links

Tuesday, November 3, 2009

How to customize Filter Menu for ComboBoxColumn inside the grid


The below event and function will help to customize Filter Menu for ComboBoxColumn to User defined values in a Grid.

The below codes will populate the Filter ComboBoxColumn with values "Yes" / "No" instead of deafault value "Checked / Unchecked"


The below Event is raised which will enable the cells editors displayed within the auto filter row cells to be initialized.

//Event to be raised
Grid.AutoFilterCellEditorInitialize +=new ASPxGridViewEditorEventHandler(gvSubstitutions_AutoFilterCellEditorInitialize);

// Function to replace the text Checked /Unchecked wiht Yes/No in the filter of the ASPxComboBox column
protected void gvSubstitutions_AutoFilterCellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
if (e.Column.FieldName == "Active")
{
(e.Editor as ASPxComboBox).Items.Clear();
(e.Editor as ASPxComboBox).Items.Add("Yes", true);
(e.Editor as ASPxComboBox).Items.Add("No", false);
}
}

Labels: , , , ,

Tuesday, October 20, 2009

Creating a ComboBox Column in DevExpress Grid and Populating it

Craeting a simple ComboBoxColumn in a grid and populating the combo box from Jan..Dec...

{
GridViewDataComboBoxColumn gridCbxMonth = new GridViewDataComboBoxColumn();
gridCbxMonth.Caption = "Month";
gridCbxMonth.FieldName = "Month";
gridCbxMonth.PropertiesComboBox.DropDownStyle = DropDownStyle.DropDown;
gridCbxMonth.PropertiesComboBox.Width = Unit.Pixel(90);
PopulateMonth(gridCbxMonth);
grid.Columns.Add(gridCbxMonth);
}
private void PopulateMonth(GridViewDataComboBoxColumn Month)
{
DateTime dt = new DateTime();

Month.Items.Add("ALL");
for (int i = 0; i < 12; i++)
{
Month.Items.Add(dt.AddMonths(i).ToString("MMMM"));
}
Month.SelectedIndex = 0;
}

Labels: , , , , , , ,