Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1285
Filter combobox based on column in dataTable
posted

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