[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

how to populate datagridview using through list(of..)

Hi experts,
   i'm struggling with populating datagridview using values stored in my list. so for instance,
   
        Dim inward As New List(Of InwardGoods)
        Dim strDate As Date = dtp1.Value

        inward = InwardGoods_Sigs.GetInwardGoodslist(strDate.ToShortDateString)

i have these codes , and a dgvReceipt defined, how do i populate it with the values in inward? any easy way? any help would be great
0
miketonny
Asked:
miketonny
  • 2
  • 2
1 Solution
 
ZhaolaiCommented:
Try
dgvReceipt.DataSource = inward
0
 
miketonnyAuthor Commented:
nothing happened, although when i run debug inward did have the table values in there. heres my code in form.vb


        dgvReceipt.ScrollBars = ScrollBars.Vertical
        dgvReceipt.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        dgvReceipt.ReadOnly = True


        dgvReceipt.Columns.Add("username", "Name")
        dgvReceipt.Columns.Add("InwardTime", "Inward Time")
        dgvReceipt.Columns.Add("SignTime", "Time Signed")
        dgvReceipt.Columns.Add("sgiReceive", "Person Signed")
        dgvReceipt.Columns.Add("AddNote", "Notes")
        dgvReceipt.Columns.Add("ticketnumber", "Ticket Number")

        Dim inward As New List(Of InwardGoods)
        Dim strDate As Date = dtp1.Value

        inward = InwardGoods_Sigs.GetInwardGoodslist()

        dgvReceipt.DataSource = inward


and heres the code i have in shared function

    Public Shared Function GetInwardGoodslist() As List(Of InwardGoods)
        Dim inwardgood As New InwardGoods
        Dim connection As OdbcConnection = DatabaseConnection.VisionDB()
        Dim selectStatement As String

        selectStatement = "SELECT TicketNumber, InwardTime, SignTime, InwardTo, SigReceive, AddNotes " _
                & "FROM InwardGoods " 
     
        Dim selectCommand As New OdbcCommand(selectStatement, connection)
        connection.Open()
        Dim reader As OdbcDataReader = selectCommand.ExecuteReader(CommandBehavior.CloseConnection)
        Dim inward As New List(Of InwardGoods)
        Do While reader.Read
            Dim iu As New InwardGoods
            iu.TicketNumber = reader.GetValue(0)
            iu.InwardTime = reader.GetValue(1)
            iu.SignTime = reader.GetValue(2)
            iu.InwardTo = reader.GetValue(3)
            iu.SigReceive = reader.GetValue(4)
            iu.AddNote = reader.GetValue(5)
            inward.Add(iu)
        Loop
        reader.Close()

        Return inward
    End Function
0
 
ZhaolaiCommented:
Here is the link I referred to:
http://dotnetperls.com/datagridview-vbnet

The code in Using Objects section works fine in my testing using List.
0
 
miketonnyAuthor Commented:
thank you very much, it worked in fact as i deleted all the columns before populate datagrid through list
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now