How to Display all associated subtask with specific taskId (Parent/Child relationship) --XAMARIN FORMS

v12doom 21 Reputation points
2022-12-08T11:39:18.397+00:00

I am new to Xamarin Forms and I am trying to create a task app. In the app, there will be the task list page and when the user selects a task, it will bring to the task view page. In the task view page, it will display the task details and the subtasks. The issue is that I can't figure out how to display the associated subtasks for the specific task id.

I'm Trying to make a todo task app with subtasks.

My github repo for code:-- https://github.com/vishu2219/Todolist-new.git

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,289 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,631 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 25,841 Reputation points Microsoft Vendor
    2022-12-09T10:00:06.69+00:00

    Hello @v12doom ,

    In the task view page, it will display the task details and the subtasks. The issue is that I can't figure out how to display the associated subtasks for the specific task id.

    I check the source code your provided, there is a ListView to display the detailed task on Subtask page, an Entry and three buttons to add/delete/cancel task(There is also a ToolbarItem to add subtask). You want to select one item on MainPage, then display the task list (or click the ToolbarItem to add a task), then select a task to navigate to Subtask, right? If so, you can refer to the following code:

    On Subtask Page:

    async void OnItemAdded(object sender, EventArgs e)  
            {  
                var item = (task)BindingContext;  
                await Navigation.PushAsync(new subtaskadd()  
                {  
                    BindingContext = new subtask()  
                    {  
                        taskId = item.Id// ass a new subtask, pass the taskId   
                    }  
                }) ;  
            }  
            async void OnClicklist(object sender, SelectedItemChangedEventArgs e)  
            {  
                if (e.SelectedItem != null)  
                {  
                    await Navigation.PushAsync(new subtaskadd()  
                    {  
                        BindingContext = e.SelectedItem as subtask  
                    });  
                }  
            }  
    

    On database.cs

     public async Task<int> SaveItemAsync2(subtask item)  
            {  
                List<subtask> items = await Database.Table<subtask>().Where(i => i.Id == item.Id).ToListAsync();// check if the subtask exists in the table  
                if (items.Count != 0)  
                {// if it is in the table, you can update  
                    subtask st = items[0];  
                    st.taskId = item.taskId;  
                    st.sub = item.sub;  
                    return await Database.UpdateAsync(st);  
                }  
                else  
                {  
                    return await Database.InsertAsync(item);  
                }  
      
            }  
    

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful