I'm new using infragistics so this might be a simple question, so here goes:I have a UltraGridColumn that has style of ColumnStyle.DropDownList. The column ValueList is set to a BindableValueList. All this is wired up in the InitLayout event method.void ultraGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e) Once that method completes, I have a dropdown with values as expected.Now the goal is to remove specific items from the dropdown list when user clicks it. I added this
ugc.Editor.BeforeEnterEditMode += Editor_BeforeEnterEditMode;
to the InitLayout event methodWhen this method - void Editor_BeforeEnterEditMode(object sender, CancelEventArgs e) is called, I create a new BindableValueList & BindingSource. I wire up those two objects like this: UltraGridColumn ugc =ultraGrid.DisplayLayout.Bands[0].Columns[this.dataSet.dataTable.CLASS_IDColumn.ColumnName];
var bvl = new BindableValueList();
var bs = new BindingSource(components);
bs.DataSource = this.dataSet;
bs.DataMember = this.dataSet.dataTable.TableName;
bs.Filter = "RETIRED = 'N'";
bvl.DisplayMember = this.dataSet.dataTable.NAMEColumn.ColumnName;
bvl.ValueMember = this.dataSet.dataTable.CLASS_IDColumn.ColumnName;
bvl.SortStyle = ValueListSortStyle.Ascending;
bvl.BindingContext = BindingContext;
bvl.DataSource = bs; ugc.Style = ColumnStyle.DropDownList; ugc.ValueList = bvl;
The problem is this: When the Editor_BeforeEnterEditMode completes, the value in the cell changes from the Name field value to the ClassId value. It only changes for an item that has a value of IS_RETIRED. It is as if I reversed the BindableValueList display and value member.The overall goal here is to remove specific items from the dropdown list so user cannot select that value again.For example I have a item that was already added to the grid that has a value of IS_RETIRED = 'Y'. I don't want to remove this value from the existing list of items in the grid, however I want to make sure that when user attempts to edit, items that have a value of IS_RETIRED = 'Y' are removed from the list so they cannot be selected.Hope that makes sense, thanks for the input
Hi Galahad,
I don't think the approach you are taking here is going to work. The ValueList in this case is translating DataValue to DisplayText in the grid cell. This conversion doesn't just happen when the cell is in edit mode, it happens all the time, every time the cell paints. So by changing the ValueList and removing items, you are breaking the translation for other cells.
So you need to keep the entire ValueList intact all the time.
What I would do, instead is use UltraCombo or UltraDropDown instead. You could bind o the same data source you are using now - but just keep the list populated with all possible values. Then you can filter the list to only show valid items when the user drops it down.
Thanks for the fast response. Your answer makes perfect sense. So bear with me pls, if I understand you correctly I need to first make change to UltraGrid_InitializeLayout method by creating new instance of UltraCombo as shown below:
UltraGridColumn ugc = e.Layout.Bands[0].Columns[this.DataSet.DataTable.JOB_CLASS_IDColumn.ColumnName]; UltraCombo uc = new UltraCombo();
BindingSource bs = new BindingSource(this.DataSet, this.DataSet.DataTable.TableName);
uc.BindingContext = this.BindingContext; uc.DisplayMember = this.DataSet.DataTable.NAMEColumn.ColumnName; uc.ValueMember = this.DataSet.DataTable.CLASS_IDColumn.ColumnName; uc.DataSource = bs; ugc.EditorComponent = uc;This gives me the ultra combo rendered as expected.Where I'm a little confused is how I filter the list when the Editor_BeforeEnterEditMode event method is called.I cast my sender in the Editor_BeforeEnterEditMode method as UltraGridComboEditor, see below:void Editor_BeforeEnterEditMode(object sender, CancelEventArgs e) { UltraGridComboEditor combo = sender as UltraGridComboEditor;However when I try to get to the combo valuelist to remove what I want, I cannot access it...what am I missing here?
So I have made some progress, based on your suggestion, I implemented UltraDropDown in my grid init layout method.See below:
private void ultraGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e) { UltraGridColumn ugc = e.Layout.Bands[0].Columns[this.DataSet.DataTable.CLASS_IDColumn.ColumnName]; UltraDropDown uc = new UltraDropDown();
uc.BindingContext = this.BindingContext; uc.DisplayMember = this.DataSet.DataTable.NAMEColumn.ColumnName; uc.ValueMember = this.DataSet.DataTable.LASS_IDColumn.ColumnName; uc.DataSource = bs; ugc.ValueList = uc; ugc.Editor.BeforeEnterEditMode += Editor_BeforeEnterEditMode;
return;
}
Then in my BeforeEnterEditMode method I access the DataSource and filter as needed. See below:void Editor_BeforeEnterEditMode(object sender, CancelEventArgs e) { EditorWithCombo combo = sender as EditorWithCombo; UltraGridCell activeCell = this.ultraGrid.ActiveCell; UltraGridColumn ugc = this.ultraGrid.DisplayLayout.Bands[0].Columns[this.DataSet.DataTable.CLASS_IDColumn.ColumnName];
string currentClassId = this.ultraGrid.ActiveCell.Value.ToString(); var vl = combo.ValueList as UltraDropDown; var bs = vl.DataSource as BindingSource; bs.Filter = "RETIRED_FLAG = 'N' AND CLASS_ID <> " + currentClassId;
vl.DisplayMember = this.DataSet.DataTable.NAMEColumn.ColumnName; vl.ValueMember = this.DataSet.DataTable.CLASS_IDColumn.ColumnName; vl.BindingContext = BindingContext; vl.DataSource = bs; ugc.ValueList = vl; return;
}However, I'm still getting the same behavior as before where the new ValueList is translating DataValue to DisplayText.I'm kinda at a loss on how to get this working, thanks for your help
Hi,
You are on the right track here, but you need to let the UltraDropDown do the filtering. Filtering the data source will end up with the same problem as before, because the editor will try to translate a DataValue to DisplayText and won't find the item on the list. So something like this:
void Editor_BeforeEnterEditMode(object sender, CancelEventArgs e) { this.ultraGrid = this.ultraGrid1; EditorWithCombo combo = sender as EditorWithCombo; UltraGridCell activeCell = this.ultraGrid.ActiveCell; string currentClassId = activeCell.Value.ToString(); var vl = combo.ValueList as UltraDropDown; vl.DisplayLayout.Bands[0].ColumnFilters.ClearAllFilters(); var columnFiltersRetiredFlag = vl.DisplayLayout.Bands[0].ColumnFilters["RETIRED_FLAG"]; columnFiltersRetiredFlag.FilterConditions.Add(FilterComparisionOperator.Equals, 'N'); var columnFiltersClassId = vl.DisplayLayout.Bands[0].ColumnFilters["Class_ID"]; columnFiltersClassId.FilterConditions.Add(FilterComparisionOperator.NotEquals, currentClassId); return; }
Also... I would probably use the AfterCellActivate or AfterEnterEditMode event of the grid, rather then rely on an event on the editor.
Awesome now I see why you suggested to use the UltraCombo, I been stuck thinking I could use the binding source filter but that does not work for this requirement.I implement your snippet and it worked great. I had to remove the last filter b/c I actually need to save the current ActiveCell contents off to the "side" so I can add that back into my list after I do the filter.Why is that? Because if a user is clicks the dropdown for a retired class, but then changes their mind and wants to keep the retired class, I need to have that option still available in the dropdown.
Galahad Phillips said:Why is that? Because if a user is clicks the dropdown for a retired class, but then changes their mind and wants to keep the retired class, I need to have that option still available in the dropdown.
Makes sense. Glad you got it all sorted out. :)
Estimated as I can do the following: in a form I have a ultracomboeditor I want when selecting a stored value process is executed and the result is loaded into a UltraGrid. Thanks in advance