Solved

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

Posted on 2010-11-29
4
469 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
ID: 34236209
Try
dgvReceipt.DataSource = inward
0
 
LVL 2

Author Comment

by:miketonny
ID: 34236322
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
ID: 34236374
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
ID: 34236858
thank you very much, it worked in fact as i deleted all the columns before populate datagrid through list
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

920 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

16 Experts available now in Live!

Get 1:1 Help Now