I bind the dataGrid to a dataTable, and has for example these columns Name, Type, Option. Option is a combobox which I have another datatable to fill it with. What I need to accomplish is when user uses Option combobox it has only items that are pertinent to the Type column.
So:Option = AAA-C,AAA-E,BBB-C,BBB-E,FFF-E,DDD-C
When Type = V only show the ones that end with C
When Type = E only show the ones that end with E
I was thinking I can filter the option table when user select record. Here is the event handler for RecordActivating. cp is the ComboBoxItemsProvider for the combobox:
private void xamDataGrid1_RecordActivating(object sender, Infragistics.Windows.DataPresenter.Events.RecordActivatingEventArgs e) { //clear filter cp.Items.Filter = null; DAL.DataSetPrjCustFields.vDCS_ProjectLineDCSCustomFieldsRow prjLine = (DAL.DataSetPrjCustFields.vDCS_ProjectLineDCSCustomFieldsRow)((DataRecord)e.Record).DataItem; cp.Items.Filter = delegate(object obj) { DAL.DataSetPrjCustFields.tPA00005Row task = (DAL.DataSetPrjCustFields.tPA00005Row)obj; switch (prjLine.ResourceType) { case "V": return task.chrTaskName.EndsWith("C"); break; case "E": return task.chrTaskName.EndsWith("E"); default: break; } return false; }; }
I get an error when I run the code. The CanFilter property in Items is false.
Is there another way to accomplish this?
Thanks
Rick
Oh, that is a much simplier solution.
Many thanks
Hello,
There is a quicker way to get the editor of a cell. The CellValuePresenter - which is the visual representation of the cell exposes an Editor property. This is the current value editor of the cell. You can get the CellValuePresenter of a cell by calling the its static method FromCell or FromRecordAndField.
As I can see from your code, you are trying to get the editor (in your case XamComboEditor) in the CellActivating event. You can do this with this code snippet :
CellValuePresenter cvp =CellValuePresenter.FromCell(e.Cell);
if (cvp.Editor is XamComboEditor)
{
XamComboEditor editor = cvp.Editor as XamComboEditor;
}
which will reduce the code and will spare you all that going up and down the element tree with the Utilities methods.
Note: These utilities methods (GetAncestor-GetDescendant) are generally used to search and find elements in the control templates (for example the SortIndicator element inside the LabelPresenter).
I figured it out I have a attached the code if anyone wants to know how to do it or has a better way.
So I made a class and populated a observableCollection with the rows from datatable and then use a CollectionView as my source for comboBox. Now I am able to filter but when I do the items in the combobox do not get refresh. is there a way to get the instance of the edit control? I want to see if there is a way to force it to refresh?