Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
hi all
 
I wrote the below code using get and set method.
 
Imports System.Collections.Generic
Imports System.Text
Imports System
Public Class setandget
 
    Public Sub New()
 
        'This call is required by the designer.
        InitializeComponent()
 
        'Add any initialization after the InitializeComponent() call.

    End Sub
 
    Public Sub New(ByVal title As String, ByVal year As Integer, ByVal director As String)
        InitializeComponent()
        Me.p_title = title
        Me.p_year = year
        Me.p_director = director
    End Sub
    Private p_title As String = String.Empty
    Private p_year As Integer = 0
    Private p_director As String = String.Empty
    Public Property T1 As String
        Get
            Return p_title
        End Get
        Set(ByVal value As String)
            p_title = value
        End Set
    End Property
    Public Property Y1() As Integer
        Get
            Return p_year
        End Get
        Set(ByVal value As Integer)
            p_year = value
        End Set
    End Property
    Public Property D1() As String
        Get
            Return p_director
        End Get
        Set(ByVal value As String)
            p_director = value
        End Set
    End Property
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
 
    End Sub
 

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Dim people As List(Of setandget) = New List(Of setandget)()
 
        ' people.Add(New setandget())
        people.Add(New setandget("a", 2012, "b"))//want to display this in datagrid
 
        DataGrid1.ItemsSource = people
        '  DataGrid1.ItemsSource = people

 
    End Sub
End Class
 
 
The value i want to display in the grid at button click
 
Please tell me where i am wrong
Posted 24-Jan-13 0:04am
Comments
Sandeep Mewara at 24-Jan-13 9:41am
   
Your code snippet is little odd - have un-necessary line and is confusing. What exactly are you doing?
BTW, is it compiling?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

My suggestion:
1. Put people in separate class
2. You might miss: DataGrid1.AutoGenerateColumns = True
Imports System.Collections.Generic
Imports System.Text
Imports System
 
Public Class setandget
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Dim listPeople As List(Of People) = New List(Of People)()
        listPeople.Add(New People("a", 2012, "b"))
        DataGrid1.AutoGenerateColumns = True
        DataGrid1.ItemsSource = listPeople
    End Sub
 
End Class
 
Friend Class People
 
    Public Sub New(ByVal title As String, ByVal year As Integer, ByVal director As String)
        Me.p_title = title
        Me.p_year = year
        Me.p_director = director
    End Sub
 
    Private p_title As String
    Private p_year As Integer
    Private p_director As String
 
    Public Property T1 As String
        Get
            Return p_title
        End Get
        Set(ByVal value As String)
            p_title = value
        End Set
    End Property
 
    Public Property Y1() As Integer
        Get
            Return p_year
        End Get
        Set(ByVal value As Integer)
            p_year = value
        End Set
    End Property
 
    Public Property D1() As String
        Get
            Return p_director
        End Get
        Set(ByVal value As String)
            p_director = value
        End Set
    End Property
 
End Class
 
Hope this helps.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100