Solved

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

Posted on 2010-11-29
4
471 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

856 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