C
C#•2w ago
cipro

WPF - Binding json data into datagrid and datagrid updates during runtime

Hey guys, I have attached screenshots here to help understand what im trying to do. so in my json file theres a bunch of usernames that are already there and during runtime i will want to add and delete logins (as the admin staff can do that). my issue here is that im trying to make the data grid output that data and read everything from the json file but i dont know the actual code for that in my XAML and cs. i tried the itemsource binding syntax but that didnt seem to work (o maybe it does but i didnt know what to put in my cs bit.)
No description
No description
13 Replies
leowest
leowest•2w ago
https://wpf-tutorial.com/datagrid-control/introduction/ then start by understanding how to use the control $json
MODiX
MODiX•2w ago
How to serialize JSON in C# - .NET
Learn how to use the System.Text.Json namespace to serialize to JSON in .NET. Includes sample code.
How to deserialize JSON in C# - .NET
Learn how to use the System.Text.Json namespace to deserialize from JSON in .NET. Includes sample code.
leowest
leowest•2w ago
and if u dont know how to load/save the json
cipro
cipro•2w ago
thanks i'll be honest i read the first link and it still didnt help because it didnt show how to load list data from a json file but i kindaaa figured it out in the end
leowest
leowest•2w ago
if u read the first link you can see it creates and populates a list yes?
cipro
cipro•2w ago
yeah my issue is that it populates a list that it creates in the same file i need to bind a list thats in an external file and read that file too
leowest
leowest•2w ago
no that is 1 step of how it works the 2nd step is you would have a method that loads your json into that list the idea with the first link is so you understand that populating a list and then setting the datagrid.ItemSource is how it populates the UI the second link shows u how to read your json into a list so all u have to do is connect 1 and 2 with the list you get from deserializing your json on the 3rd link u set the ItemSource
leowest
leowest•2w ago
No description
leowest
leowest•2w ago
1) you see it creates the list, populates it 2) it then sets the ItemsSource when you deserialize your json, you already have item 1 so all that is left is to set item 2
cipro
cipro•2w ago
i see so for the method i would create that myself? sorry im still confused exactly how im supposed to implement it 😭 because the thing is i understand that you gotta combine 1 and 2 im just a bit confused where to start though because i dont really know the sytax for linking it with a method to my json file
leowest
leowest•2w ago
@cipro can you provide your json class you deserialize and how you're doing it right now
cipro
cipro•2w ago
@leowest nevermind i figured it out thank you though! codings a bit of an up and down hill to be honest lol
leowest
leowest•2w ago
np, if u provide your code I can see where your getting stuck and explain further thou
Want results from more Discord servers?
Add your server