locked
please help.... filtering multiple collection views using checkboxes...... RRS feed

  • Question

  • .... i'm a noob at this so please do be offended by my ignorance. OK i am working on a wpf project.... "recipes"

    it consists of a master/detail type pattern with 1 parent table and 7 children tables.... i am using collection views and thankfully everything works on my forms as far as  insert, add, update, and delete. my problem is i want to filter the master collection view using check boxes and i have no idea how to accomplish this.... I've read so many posts on it but can not find one that applies to my problem.

    here's the problem  exactly. my data set consists of 8 tables. 5 of them are nothing but check box answers. these are the answers i need to filter the main view by. ( whether by 1 table or a combination of all 5)

    so should i create a collection view for each table i want to filter by and if so... how do i write the parts for the check boxes. i watched the msdn how to videos to get this far, but there are no tutorial videos dealing with check boxes, filtering collection views using check boxes. nothing.

    and if i should create a separate collection view for each table, how would i filter the different views into a single list view?

    any and all help would be extremely extremely appreciated.

                                               thanks



    Adam

    Tuesday, May 15, 2012 3:45 AM

All replies

  • ..... i'm a noob at this so please do be offended by my ignorance. OK i am working on a wpf project.... "recipes"

    it consists of a master/detail type pattern with 1 parent table and 7 children tables.... i am using collection views and the EF. thankfully everything works on my forms as far as  insert, add, update, and delete. my problem is i want to filter the master collection view using check boxes and i have no idea how to accomplish this.... I've read so many posts on it but can not find one that applies to my problem.

    here's the problem  exactly. my data set consists of 8 tables. 5 of them are nothing but check box answers. these are the answers i need to filter the main view by. ( whether by 1 table or a combination of all 5)

    so should i create a collection view for each table i want to filter by and if so... how do i write the parts for the check boxes. i watched the msdn how to videos to get this far, but there are no tutorial videos dealing with check boxes, filtering collection views using check boxes. nothing.

    and if i should create a separate collection view for each table, how would i filter the different views into a single list view?

    any and all help would be extremely extremely appreciated.

                                               thanks


    Adam



    • Edited by ajk825 Tuesday, May 15, 2012 3:26 PM
    • Moved by Bob Wu-MT Wednesday, May 16, 2012 5:32 AM (From:Windows Forms General)
    • Merged by Annabella Luo Thursday, May 17, 2012 3:30 AM
    Tuesday, May 15, 2012 3:41 AM
  • Hi Adam,

    I'm not quite sure how this would work for your exact example but I've found a good method to change a simple DataGridView based on a checkbox being ticket/unticked. Whilst this won't be an instant fix for you I hope it demonstrates the methodology required:

            //This is the event for a standard checkbox changing status
            private void checkBox1_CheckedChanged(object sender, EventArgs e)
            {
                if (checkBox1.Checked) //if the checkbox is ticked then
                    this.customersBindingSource.Filter = "Country = 'Germany'";
                    //The customersBindingSource is the binding source automatically generated when using a dataset through the designer,
                    //please put in the relevant BindingSource being used by your table.
                    //Also please note the syntax for the filter -> "Column Name = 'FilterValue'". You could easily code this using string parameters like:
                    //string colName = "Column";
                    //string filterVal = "FilterVal";
                    //this.yourBindingSource.Filter = colName + " = '" + filterVal + "'"; //I don't know if there is a better way to do this, perhaps using a stringbuilder.
                else if (!checkBox1.Checked)
                    this.customersBindingSource.RemoveFilter();
                    //Again substitute the BindingSource with the name of yours.
            }

    Nick Sandel (Software Tester) New to C# since December 2011

    Tuesday, May 15, 2012 10:59 AM
  • hi nick. thanks for the response. not using data sets though. using collection views and the entity framework. it's telling me something about using the Predicate (of Object) ??? but this does work in another project on the same line so... thanks.


    Adam

    Tuesday, May 15, 2012 3:12 PM
  • Hi Adam, sorry my first post wasn't very useful for you :P

    I haven't worked with Collection views myself yet but I did a quick search on the MSDN library and this article looks promising for you:

    http://msdn.microsoft.com/en-us/library/system.windows.data.collectionview.filter.aspx


    Nick Sandel (Software Tester) New to C# since December 2011

    Tuesday, May 15, 2012 4:02 PM
  • Hi Adam,

    According to your description, you have a WPF issue. I will move it to the WPF forum for better support.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, May 16, 2012 5:31 AM
  • i have the same posted question there also..... 43 views and no responses.

    do you know of any links or tutorials dealing with check boxes and filtering collection views using them? that would be extremely helpful. thanks.


    Adam

    Wednesday, May 16, 2012 6:06 AM
  • Hi Adam,

    I am sorry that I have not understood your main concern clearly, if you want to complete the fliter feature, you could use ICollectionView interface, refer to below code snippet to get the view:

    ICollectionView view = CollectionViewSource.GetDefaultView(collection);

    Collection could be ItemsControl.ItemsSource as well.

    and then you could set the filter property of the CollectionViewSource.filter object,

    view.Filter = delegate (object o) 
     { return ((Item)o).Category = filterComboBox.SelectedItem; } 

    As for the CheckBox part, you could handle the Checked event, I do not thing the checkbox has relationship with filter.

    If i have misunderstood your concern, please let me know.

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Sheldon _Xiao Thursday, May 24, 2012 7:04 AM
    • Unmarked as answer by ajk825 Wednesday, June 13, 2012 3:47 PM
    Wednesday, May 16, 2012 12:00 PM
  • thank  you for the response... i'm used to winforms and using datasets. these collection views and wpf in general are throwing me off...  anyways I'm looking into this option now... really hoping it works. you said that you weren't sure if the checkbox has a relationship with filter... What about the "ischecked ="  property I've seen?

    thanks again. i'll let ya know how it goes.


    Adam

    Thursday, May 17, 2012 4:15 AM
  • Hi ajk825,

    Yes, you could use IsChecked property to achieve your goal, for example, in wpf you could trigger this property or binded to this property, both are good method.

    additional, I am marking your issue as "Answered", if you need further discusstion, please let me know.

    best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 24, 2012 7:04 AM
  • this didn't help.

    sorry


    Adam

    Tuesday, June 12, 2012 5:49 AM
  • Hi ajk825,

    Could you tell me the situation of your issue now?

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 12, 2012 5:55 AM
  • hi Sheldon ... sorry it took so long to get back with you about this problem. i'm sorry i did a horrible job explaining my situation above. please refer to : http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b0eb212e-1109-4cd4-b871-9cb8c793293c for a better explanation of the problem. thanks.

    Adam

    Tuesday, June 12, 2012 6:35 AM