TurboTilly
New member
- Joined
- Nov 3, 2013
- Messages
- 1
- Programming Experience
- 1-3
Hi guys,
I am new to this forum and hope that all of you can bear with me since I am relatively 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"
and I am currently adding data at the Application Startup in Application.XAML.vb
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)
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
I am new to this forum and hope that all of you can bear with me since I am relatively 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"
VB.NET:
[COLOR=#666666][FONT=Segoe UI]Imports System.Data[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI]Imports System.ComponentModel[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI]Public Class DataModel[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Implements INotifyPropertyChanged[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] 'Public Sub New(ByVal _DT As DataView)[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] ' Me.TestDataView = _DT[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] 'End Sub[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Private _testDataView As New DataView[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Public Property TestDataView() As DataView[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Get[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Return _testDataView[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] End Get[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Set(value As DataView)[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] _testDataView = value[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] InvokePropertyChanged("TestDataView")[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] End Set[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] End Property[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Public Sub InvokePropertyChanged(Properties As String)[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(Properties))[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] End Sub[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI]End Class[/FONT][/COLOR]
and I am currently adding data at the Application Startup in Application.XAML.vb
VB.NET:
[COLOR=#666666][FONT=Segoe UI]Imports System.Data[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI]Class Application[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] ' can be handled in this file.[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Private Sub Application_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Dim dataTableView As DataModel[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Dim dataTable As DataTable[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] dataTable.Columns.Add("DeptID", GetType(System.Int32))[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] dataTable.Columns.Add("DepartmentName", GetType(System.String))[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] dataTable.Columns.Add("HOD", GetType(System.String))[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] dataTable.Columns.Add("FacultyCount", GetType(System.String))[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Dim row As DataRow = dataTable.NewRow()[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] row("DeptID") = 1[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] row("DepartmentName") = "CS&E"[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] row("HOD") = "John"[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] row("FacultyCount") = 20[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] dataTable.Rows.Add(row)[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] row = dataTable.NewRow()[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] row("DeptID") = 2[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] row("DepartmentName") = "Mech"[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] row("HOD") = "Bo Yo"[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] row("FacultyCount") = 23[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] dataTable.Rows.Add(row)[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] dataTableView.TestDataView = dataTable.DefaultView[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] End Sub[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI]End Class[/FONT][/COLOR]
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)
VB.NET:
[COLOR=#666666][FONT=Segoe UI]<Window x:Class="MainWindow"[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] DataContext="DataModel"[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] Title="MainWindow" Height="350" Width="525">[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] <Grid>[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] <Grid.ColumnDefinitions>[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] <ColumnDefinition Width="41*"/>[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] <ColumnDefinition Width="6*"/>[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] </Grid.ColumnDefinitions>[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] <DataGrid ItemsSource="{Binding TestDataView}" HorizontalAlignment="Left" Height="273" Margin="10,25,0,0" VerticalAlignment="Top" Width="480" Grid.ColumnSpan="2" />[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI] </Grid>[/FONT][/COLOR]
[COLOR=#666666][FONT=Segoe UI]</Window>[/FONT][/COLOR]
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