Solved

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

Posted on 2010-11-29
4
473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to take different types of Oracle backups using RMAN.

687 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