Hi guys,
so I am new to VB.NET and am still trying to wrap my head around MVVM. I think it is a great way of designing an application; however, all I am able to track down on the web are C$ examples and only very little "Over my head" info given in vb.net. Unfortunately I don't have enough time to learn C$ so applying mvvm to vb.net proves difficult at best.
Here is my diellema and please bear with me here if this isn't the correct way of doing things, I am just trying to learn. I have a datatable that I eventually want to show on multiple gridviews in multiple windows.
I created a class called "DataModel"
Imports System.Data
Imports System.ComponentModel
Public Class DataModel
Implements INotifyPropertyChanged
Private _testDataView As New DataView
Public Property TestDataView() As DataView
Get
Return _testDataView
End Get
Set(value As DataView)
_testDataView = value
InvokePropertyChanged("TestDataView")
End Set
End Property
Public Sub InvokePropertyChanged(Properties As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(Properties))
End Sub
Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
End Class
and I am currently adding data at the Application Startup in Application.XAML.vb
Imports System.Data
Class Application
Private Sub Application_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
Dim dataTableView As DataModel
Dim dataTable As DataTable
dataTable.Columns.Add("DeptID", GetType(System.Int32))
dataTable.Columns.Add("DepartmentName", GetType(System.String))
dataTable.Columns.Add("HOD", GetType(System.String))
dataTable.Columns.Add("FacultyCount", GetType(System.String))
Dim row As DataRow = dataTable.NewRow()
row("DeptID") = 1
row("DepartmentName") = "CS&E"
row("HOD") = "John"
row("FacultyCount") = 20
dataTable.Rows.Add(row)
row = dataTable.NewRow()
row("DeptID") = 2
row("DepartmentName") = "Mech"
row("HOD") = "Bo Yo"
row("FacultyCount") = 23
dataTable.Rows.Add(row)
dataTableView.TestDataView = dataTable.DefaultView
End Sub
End Class
Here is the MainWindow.xaml (I only created a datagrid to display the datatable and set the datacontext of the window to the class DataModel)
<Window x:Class="MainWindow"
DataContext="DataModel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="41*"/>
<ColumnDefinition Width="6*"/>
</Grid.ColumnDefinitions>
<DataGrid ItemsSource="{Binding TestDataView}" HorizontalAlignment="Left" Height="273" Margin="10,25,0,0" VerticalAlignment="Top" Width="480" Grid.ColumnSpan="2" />
</Grid>
</Window>
The problem is, there are no errors but I can't see any values in my datagrid. I really don't know what I am doing wrong here. Would any of you guys be willing to help me out? Thank you very much in advance