在get和set方法中需要帮助 [英] Need help in get and set method

查看:82
本文介绍了在get和set方法中需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我用get和set方法编写了下面的代码。



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

推荐答案

我的建议:

1.把人分开来

2.您可能错过:DataGrid1.AutoGenerateColumns = True

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.


这篇关于在get和set方法中需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆