Quantcast
Channel: VBForums - WPF, WCF, WF
Viewing all articles
Browse latest Browse all 256

[VB/WPF] How to populate a Datagrid from a Dictionary Of Class

$
0
0
Hi there,

I'm creating a simulation game with RPG and Visual Novel elements. One of its primary requirements is that it supports overlapping of alpha transparent PNG images, so I switched to WPF for its seamless functionality in that respect.

However... I'm amazed at how my previous WinForms code has become useless at some parts, but I was able to cope until now. I'm banging my head with something that should be easy (in WinForms it was) to do: populate a Datagridview control with data from the main dictionary of class of the game.

However, my previous code is now useless because Datagrids in WPF doesn't have a Rows.Add method. This is what I had in WinForms...:
Code:

Public Sub PopulateDebugPersonsDataGrid()
    datagridDebug.Rows.Clear()
    For n As Integer = 1 To students_count
        datagridDebug.Rows.Add({n, studentList("student" & n).firstname, studentList("student" & n).lastname
    Next
End Sub

Where...:
studentList is a Dictionary(of Person) created at run time (new key,Person pairs could be added later).
students_count is an integer variable containing the current number of Person instances.
datagridDebug is a Datagridview control made at design time with all of its headers filled in.

This is a simplified version for the sake of visibility because that Person class has a lot more properties.

Well, my problem is that WPF doesn't support this method and it seems that I need to "bind a datasource" or something like that. I've came across a ton of posts and articles in the past 24 hours and the best I managed to get was a grid with two columns: one displaying the dictionary keys (student1, student2...) and another for the supposed value (HHS.Person, HHS.Person) and that only because I left the Datagrid property "AutoGenerateColumns" set to True.

And needless to say, what I really need to display at the Datagrid are the firstname, lastname properties, not the name of the whole class.

Worse even, the majority of tutorials out there take for granted that if you are working with WPF then you are coding with C#... I'm really sick of getting my hopes high because a Google result seems promising to only realize that it's full of those dammed { and } symbols all over the code behind. :(

So I'll be really grateful if you guide me in the right direction.

I know this is not the first not the last time I'll say this but... it shouldn't be very strange what I'm intending to do right? :rolleyes:

Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>