Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all

I wrote the below code using get and set method.

VB
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
Comments
Sandeep Mewara 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

My suggestion:
1. Put people in separate class
2. You might miss: DataGrid1.AutoGenerateColumns = True
VB
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900