Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi...i have some code here display all data..the problem here is how can i get the second column of the data? i only can get the first column.
here is my code..can u help me?

VB
    Private Sub dbffrm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Companydbf = "C:\PAY\"
        Dim ConnectionString As String = String.Empty, sCommand As String = String.Empty
        Dim xlApp As Excel.Application = Nothing, xlWorkBook As Excel.Workbook = Nothing, xlWorkSheet As Excel.Worksheet = Nothing, xlRange As Excel.Range = Nothing
        Dim dBaseConnection As OleDb.OleDbConnection = Nothing, dBaseCommand As OleDb.OleDbCommand = Nothing
        Dim retVal As Integer = 0
        Dim reader As OleDbDataReader
        Try
            'if use visual fox pro Connect to a single DBF-file
            ConnectionString = "Provider=vfpoledb;Data Source=" & IO.Path.GetDirectoryName(Companydbf) & ";Collating Sequence=machine;"
            dBaseConnection = New OleDb.OleDbConnection(ConnectionString)
            dBaseConnection.Open()
            sCommand = "Select * from company.dbf "
            dBaseCommand = New OleDbCommand(sCommand, dBaseConnection)
            'myDA = New OleDbDataAdapter(comm)
            'dBaseCommand = New OleDb.OleDbCommand(sCommand, dBaseConnection)
            retVal = dBaseCommand.ExecuteNonQuery()

            reader = dBaseCommand.ExecuteReader()
            'Dim intCount As Decimal = 0
            ListView1.View = View.Details
            ListView1.GridLines = True
            ListView1.FullRowSelect = True
            ListView1.HideSelection = False
            ListView1.MultiSelect = False

            ListView1.Columns.Add("Company Name")
            ListView1.Columns.Add("Directory Name")




            While reader.Read()
                Dim lvi As New ListViewItem
          

                
                lvi.Text = reader("CONAME").ToString
                ' second column 
                lvi.SubItems.Add(reader("DIRNAME").ToString)

                
                ListView1.Items.Add(lvi)
                
                'intCount = intCount + 1
            End While
            dBaseConnection.Close()

        Catch ex As System.InvalidCastException
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")

        Catch ex As OleDb.OleDbException
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")

        Catch ex As System.NullReferenceException
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")

        End Try
     End Sub

Private Sub ListView1_SelectedIndexChanged(ByVal sender As  _
       System.Object, ByVal e As System.EventArgs) _
       Handles ListView1.SelectedIndexChanged

        If ListView1.SelectedIndices.Count = 0 Then Return

        Dim lvi As ListViewItem = _
            ListView1.SelectedItems(0)

        'MessageBox.Show(lvi.Text + " has been selected.")
        nxtbtn3.Enabled = True
        Companydbf = lvi.Text
        MessageBox.Show(Companydbf)
    End Sub
Posted

1 solution

VB
Private Sub ListView1_SelectedIndexChanged(ByVal sender As  _
      System.Object, ByVal e As System.EventArgs) _
      Handles ListView1.SelectedIndexChanged

       If ListView1.SelectedIndices.Count = 0 Then Return

       Dim lvi As ListViewItem = _
           ListView1.SelectedItems(0)


       nxtbtn3.Enabled = True
       Companydbf = lvi.SubItems(1).Text



   End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900