Solved

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

Posted on 2010-11-29
4
467 Views
Last Modified: 2012-08-14
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
Comment
Question by:miketonny
  • 2
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Zhaolai
Comment Utility
Try
dgvReceipt.DataSource = inward
0
 
LVL 2

Author Comment

by:miketonny
Comment Utility
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
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
Comment Utility
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
 
LVL 2

Author Comment

by:miketonny
Comment Utility
thank you very much, it worked in fact as i deleted all the columns before populate datagrid through list
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now