6 Replies - 10140 Views - Last Post: 05 May 2012 - 12:39 PM Rate Topic: -----

#1 a6yaf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 05-February 10

displaying access table in list view

Posted 11 February 2010 - 12:38 PM

i used the following code for retrieving a column items from access table and displaying it by using list view,,, and it work perfectly,,, the problem now is that i need to add another column items to the list view ... but how?????

i displayed the two columns with their headers but the problem is retrieving the items for the second column.

this is the code tha i used for the first column:

 ListView1.Items.Clear()
        Dim comm As New OleDb.OleDbCommand("select * from TEACHER", cnn)
        Try
            cnn.Open()

            Dim datareader As OleDb.OleDbDataReader
            datareader = comm.ExecuteReader

            While datareader.Read
                Dim lvi As New ListViewItem
                lvi.Text = CStr(datareader("T_ID"))
                ListView1.Items.Add(lvi)


            End While

            If datareader.HasRows Then
                ListView1.TopItem.Selected = True
                ListView1.TopItem.Focused = True
                ListView1.TopItem.EnsureVisible()
                ListView1.Select()
            End If

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
        Finally
            'connection.Close()
        End Try



Is This A Good Question/Topic? 0
  • +

Replies To: displaying access table in list view

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: displaying access table in list view

Posted 11 February 2010 - 12:55 PM

Assuming that your listview already has columns available you could just use
       While datareader.Read
                Dim lvi As New ListViewItem
                lvi.Text = CStr(datareader("T_ID"))
                lvi.subitems.add(datareader("2nd Column").tostring)
                lvi.subitems.add(datareader("3rd Column").tostring)
                ListView1.Items.Add(lvi)


            End While



etc...
Was This Post Helpful? 0
  • +
  • -

#3 a6yaf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 05-February 10

Re: displaying access table in list view

Posted 12 February 2010 - 04:39 AM

thank you CharlieMay for replying,,,but i think this is NOT what i want exactly.
i have already listview with two columns( T_ID / T_NAME ) and the code which I mentioned above is retrieving the items for only one column( T_ID ) ,,, the problem now how to retrieve the items for the second column ( T_ NAME )
where all information saved in a table in access

This post has been edited by a6yaf: 12 February 2010 - 04:41 AM

Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: displaying access table in list view

Posted 12 February 2010 - 05:25 AM

While datareader.Read
   Dim lvi As New ListViewItem
   lvi.Text = CStr(datareader("T_ID"))
   lvi.subitems.add(datareader("2nd Column").tostring) '<- the "2nd Column" is where you would put T_Name
   lvi.subitems.add(datareader("3rd Column").tostring) '<- You can remove this line it was just to show how to continue adding
   ListView1.Items.Add(lvi) '  
End While
Scroll -> for comments


lvi.subitems.add will add to the next column. You can continue adding subitems as long as those columns exist in your listview.

So this line of my example
lvi.subitems.add(datareader("2nd Column").tostring)


Would look like this in your application
lvi.subitems.add(datareader("T_Name").tostring)


Sorry, I can see where that could be confusing for someone who hasn't done this.

This post has been edited by CharlieMay: 12 February 2010 - 05:30 AM

Was This Post Helpful? 0
  • +
  • -

#5 a6yaf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 05-February 10

Re: displaying access table in list view

Posted 12 February 2010 - 12:12 PM

Thank you sooooo much CharlieMay for this explaination , i don't know how i couldn't understand what you mentioned before but i had too much pressure to finish this project and the time reach to the end.

i am pologize and thanx again :blush:
Was This Post Helpful? 0
  • +
  • -

#6 farhan_b  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 133
  • Joined: 26-February 12

Re: displaying access table in list view

Posted 02 March 2012 - 02:31 PM

        Me.CgsecurityroleBindingSource.DataMember = "cg_security_role"
        '
        'CgsecurityuserroleBindingSource
        '
        Me.CgsecurityuserroleBindingSource.DataMember = "cg_security_user_role"
        '
        'Cg_security_userBindingSource
        '
        Me.Cg_security_userBindingSource.DataMember = "cg_security_user"
        '
        'Cg_security_userTableAdapter
        '
        Me.Cg_security_userTableAdapter.ClearBeforeFill = True
        '
        'TableAdapterManager
        '
        Me.TableAdapterManager.BackupDataSetBeforeUpdate = False
        Me.TableAdapterManager.cg_security_rightTableAdapter = Nothing
        Me.TableAdapterManager.cg_security_userTableAdapter = Me.Cg_security_userTableAdapter
        Me.TableAdapterManager.tblbrachStockDTableAdapter = Nothing
        Me.TableAdapterManager.tblBranchesTableAdapter = Nothing
        Me.TableAdapterManager.tblBranchStockRTableAdapter = Nothing
        Me.TableAdapterManager.tblCustomerTableAdapter = Nothing
        Me.TableAdapterManager.tblDeliveryNoteTableAdapter = Nothing
        Me.TableAdapterManager.tblForcastTableAdapter = Nothing
        Me.TableAdapterManager.tblGoodRecievedTableAdapter = Nothing
        Me.TableAdapterManager.tblGoodsReturnedTableAdapter = Nothing
        Me.TableAdapterManager.tblInvoiceTableAdapter = Nothing
        Me.TableAdapterManager.tblLock_UnlockTableAdapter = Nothing
        Me.TableAdapterManager.tblOrderTableAdapter = Nothing
        Me.TableAdapterManager.tblPickListTableAdapter = Nothing
        Me.TableAdapterManager.tblPurDeliveryTableAdapter = Nothing
        Me.TableAdapterManager.tblSalesDeliverTableAdapter = Nothing
        Me.TableAdapterManager.tblSalesOrderTableAdapter = Nothing
        Me.TableAdapterManager.tblStockTableAdapter = Nothing
        Me.TableAdapterManager.tblSupplierTableAdapter = Nothing
        Me.TableAdapterManager.UpdateOrder = SupplyChainSystem.DataSetTableAdapters.TableAdapterManager.UpdateOrderOption.InsertUpdateDelete
        '
        'Cg_security_rightTableAdapter
        '
        Me.Cg_security_rightTableAdapter.ClearBeforeFill = True
        '
        'Form2
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(809, 469)
        Me.Controls.Add(Me.TabControl1)
        Me.Name = "Form2"
        Me.Text = "Form2"
        CType(Me.CgsecurityrightBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        Me.TabPage5.ResumeLayout(False)
        Me.TabPage5.PerformLayout()
        CType(Me.Cg_security_rightDataGridView, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Cg_security_rightBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataSet, System.ComponentModel.ISupportInitialize).EndInit()
        Me.TabPage6.ResumeLayout(False)
        Me.TabPage6.PerformLayout()
        CType(Me.DataGridView5, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Cg_security_roleBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.CgsecurityroleBindingSource1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.TabPage1.ResumeLayout(False)
        Me.TabPage1.PerformLayout()
        CType(Me.Cg_security_userDataGridView, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Cg_security_userBindingSource1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.CgsecurityuserBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        Me.TabControl1.ResumeLayout(False)
        Me.TabPage2.ResumeLayout(False)
        Me.TabPage2.PerformLayout()
        CType(Me.CgsecurityroleBindingSource2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.CgsecurityroleBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.CgsecurityuserroleBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Cg_security_userBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

Was This Post Helpful? 0
  • +
  • -

#7 Niah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-May 12

Re: displaying access table in list view

Posted 05 May 2012 - 12:39 PM

Hello, i have a problem with my program in Visual studio. Please help me!!!i'm so zero. My code in the module is:

Public Sub RecupereDonnees(ByVal login As String, ByRef Matiere As String, ByRef note As Single, ByRef coef As Byte)
Dim conn As OleDbConnection
Dim connOk As Boolean
Dim cmdSQL As OleDbCommand
Dim resSQl As OleDbDataReader
Dim lstDonnees As New ListView

Call Connection("Provider = Microsoft.ACE.OLEDB.12.0;Data Source= ..\..\ProjetProg.accdb", conn, connOk)
If connOk Then
Dim resTab As String

resTab = "select DISTINCT M.NomMat, AVG(O.Note) as [Note], C.CoefC from Matière AS M, Professeur AS P, Contrôle AS C, Obtenir AS O WHERE O.NumElev = '" & login & "' and C.NumC = O.NumC and C.NumProf = P.NumProf and P.NumMat = M.NumMat GROUP BY M.NomMat, C.CoefC"
cmdSQL = New OleDbCommand(resTab, conn)
resSQl = cmdSQL.ExecuteReader
While resSQl.Read()
Dim lvi As New ListViewItem
lvi.SubItems.Add(resSQl("Matiere").ToString)
lvi.SubItems.Add(resSQl("note").ToString)
lvi.SubItems.Add(resSQl("coef").ToString)
lstDonnees.Items.Add(lvi)
End While
resSQl.Close()
Call Deconnection(conn)
End If
End Sub

and my code in the interface is:

Private Sub lstDonnees_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstdonnees.SelectedIndexChanged
Dim login As String
Dim Matiere As String
Dim note As Single
Dim coef As Byte

login = User
Call RecupereDonnees(login, Matiere, note, coef)
lstdonnees.Items.Item(0).SubItems.Add(Matiere)
lstdonnees.Items.Item(1).SubItems.Add(note)
lstdonnees.Items.Item(0).SubItems.Add(coef)
End Sub

Thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1