Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello

i am new to programming with wpf.
I have a big Problem with an i think normal requirement.

I have a Datagrid with two Columns "Project" and "Tasks"
Each Task belongs to an Project.

Data for Projects (ObservableCollection):
Project 1
Project 2
Project 3

Data for Tasks (ObservableCollection):
Task 1 - Project 1
Task 2 - Project 1
Task 3 - Project 1
Task 4 - Project 2
Task 5 - Project 2
Task 6 - Project 3

When i select a Project in the Column "Project" i want to filter the second Column "Tasks" that only Tasks for the selected Projects are shown.

I have no Idea how i should solve that Problem.

What I have tried:

At the Moment i refresh the itemsource for the Task column every time i Change the Project column.
When i add for example two rows
Row 1: Project 1 - Task 1
Row 2: Project 2 - Task 4
i got the Problem that when i select Project 2 in the second row the itemsource for the Task column gets new data (only tasks for Project 2).
The Row 1 doesnt show task1 anymore because its not in the itemsource list.

How could i solve that Problem. Can anyone give me a sample how this requirement could be solved in an easy way?
Posted
Updated 1-Jun-17 5:13am

If you filter the Grid like that you are not going to be able to see the other projects because you only have one control.

A better design would be to have two dropdownlists - populate the 2nd list based on a selection from the first.

There is some sample code here c# - Populate WPF listbox based on selection of another listbox[^]
 
Share this answer
 
Comments
Peter Erler 2-Jun-17 7:05am    
Hi,

sorry it took a while before i could try this out.
I cant solve my Problem with the provided solution!

I think the database structure is the problem why the solution doesnt help.

The Datacontext for my WPF Window is the table "TimeRegistration"
This table contains the fields "Project", "Task", "TimeFrom" and "TimeTo".

The solution i am searching is a one grid solution.
I want to record working times for projects and tasks in an easy way.

I thought this would be easy to develope but i didnt get it running.

Could anyone provide a small sample project that fits my requirements?

Greetings from Austria
Peter
CHill60 2-Jun-17 17:33pm    
There doesn't seem to be anything wrong with your table structure. As I explained, because you are using a single Grid, once you have applied any filter you are not going to be able to see items that would allow you to filter in a different way
Hi,

sorry it took a while before i could try this out.
I cant solve my Problem with the provided solution!

I think the database structure is the problem why the solution doesnt help.

The Datacontext for my WPF Window is the table "TimeRegistration"
This table contains the fields "Project", "Task", "TimeFrom" and "TimeTo".

The solution i am searching is a one grid solution.
I want to record working times for projects and tasks in an easy way.

I thought this would be easy to develope but i didnt get it running.

Could anyone provide a small sample project that fits my requirements?

Greetings from Austria
Peter
 
Share this answer
 
Comments
Richard Deeming 1-Jun-17 12:07pm    
If you want to reply to a solution, use the "Have a Question or Comment?" button under the solution.

Do not post your comment as a "solution".
Peter Erler 2-Jun-17 7:05am    
Hi,

sorry it took a while before i could try this out.
I cant solve my Problem with the provided solution!

I think the database structure is the problem why the solution doesnt help.

The Datacontext for my WPF Window is the table "TimeRegistration"
This table contains the fields "Project", "Task", "TimeFrom" and "TimeTo".

The solution i am searching is a one grid solution.
I want to record working times for projects and tasks in an easy way.

I thought this would be easy to develope but i didnt get it running.

Could anyone provide a small sample project that fits my requirements?

Greetings from Austria
Peter

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900