[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

DATAGRIDVIEW does not display list of objects -- why not?

Posted on 2010-03-23
3
Medium Priority
?
493 Views
Last Modified: 2012-05-09
Why does the Datagrid not display the values?  (Winforms application.)
Public Class PFFAFormClass
    Public PFFAFormName As String
    Public OCFNO As String
    Public NoteType As String
    Public IndexMethod As String
End Class


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pfc As New PFFAFormClass

        pfc.NoteType = "CH"
        pfc.OCFNO = "3013"
        pfc.PFFAFormName = "Test Form"
        pfc.IndexMethod = ""

        Dim lst As New List(Of PFFAFormClass)
        lst.Add(pfc)

        Me.DataGridView1.DataSource = lst

        Me.DataGridView1.Refresh()


End Sub

Open in new window

0
Comment
Question by:codefinger
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Trideep Patel earned 2000 total points
ID: 28346209
Make property for your variables and it will works
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim pfc As New PFFAFormClass

        pfc._NoteType = "CH"
        pfc._OCFNO = "3013"
        pfc._PFFAFormName = "Test Form"
        pfc._IndexMethod = ""

        Dim lst As New List(Of PFFAFormClass)
        lst.Add(pfc)
     
        Me.DataGridView1.DataSource = lst


        Me.DataGridView1.Refresh()


    End Sub


End Class

Public Class PFFAFormClass
    Public PFFAFormName As String
    Public Property _PFFAFormName() As String
        Get
            Return PFFAFormName
        End Get
        Set(ByVal value As String)
            PFFAFormName = value
        End Set
    End Property
    Public OCFNO As String
    Public Property _OCFNO() As String
        Get
            Return OCFNO
        End Get
        Set(ByVal value As String)
            OCFNO = value
        End Set
    End Property

    Public NoteType As String
    Public Property _NoteType() As String
        Get
            Return NoteType
        End Get
        Set(ByVal value As String)
            NoteType = value
        End Set
    End Property
    Public IndexMethod As String

    Public Property _IndexMethod() As String
        Get
            Return IndexMethod
        End Get
        Set(ByVal value As String)
            IndexMethod = value
        End Set
    End Property   

End Class

Open in new window

0
 

Author Comment

by:codefinger
ID: 28365071
If no one else answers, you (trideep) get the points, but I do not think I should have to make the change you suggest.  Public variables in the class SHOULD work with the datagrid, unless I am overlooking something.  What am I overlooking?

0
 

Author Closing Comment

by:codefinger
ID: 31706013
The reason I thought public properties should work without get and set was because I did have that working for some other lists, however in that case the list was the property of another object, which somehow made GETS and SETS available to the datagrid automatically...still working out the details but this IS the RIGHT answer.....so THANKS!!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Jorge
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question