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.)
13 Replies
https://wpf-tutorial.com/datagrid-control/introduction/
then start by understanding how to use the control
$json
https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-how-to
https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/deserialization
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.
and if u dont know how to load/save the json
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
if u read the first link
you can see it creates and populates a list yes?
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
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
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
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
@cipro can you provide your json class you deserialize and how you're doing it right now
@leowest nevermind i figured it out
thank you though!
codings a bit of an up and down hill to be honest lol
np, if u provide your code I can see where your getting stuck and explain further thou