Good day,
I am very new to programming. There are hundreds of forum posts and articles on how to bind a datagrid and I am trying my damnedest to mimic them but it is not working for me.
I am just making a To Do List as practice to help me learn .NET. I have a database table called "Tasks" that I want to load any records assigned to the user(There is only 1 record for testing it right now).
In my ViewModel code, I have a subroutine that queries the database and loads it into a list(of task)
Here is my WPF Code where I want to bind the datagrid control to my GridView property in my TaskViewModel class.Code:Public Class TaskViewModel Public Property GridView As List(Of Task) Public Sub New() End Sub Public Sub CallTaskData(username As String) Dim taskData As New Task Dim db As New ProjectContext GridView = (From t In db.Tasks Where t.AssignedTo = username Select t).ToList End Sub End Class
If I do a MessageBox.Show(GridView.Item(0).AssignedTo.ToString) after I set the GridView property, it pulls data out of that list field...so I know my Gridview is loaded. So I am just screwing up the WPF binding somehow.Code:x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ProjectManagement" mc:Ignorable="d" Title="Tasks" Height="350" Width="525" Loaded="Window_Loaded"> <Window.DataContext> <local:TaskViewModel/> </Window.DataContext> <Grid> <DataGrid x:Name="dgTasks" ItemsSource="{Binding GridView}" AutoGenerateColumns="True" HorizontalAlignment="Left" Height="150" Margin="160,40,0,0" VerticalAlignment="Top" Width="347" > </DataGrid> </Grid> </Window>
Any guidance would be appreciated.




Reply With Quote
