• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1507
  • Last Modified:

Listview Items & Subitems to Datagridview

I have a listview that gets it's data from text files, I would like to take the listview data and move it to a datagridview, or use the text flies to generate a datagridview. I don't know how to read the text files into a datagridview so that's why im taking this approach. Please help with code, thanks!
0
Jack_Jones
Asked:
Jack_Jones
  • 6
  • 4
1 Solution
 
CodeCruiserCommented:
Is it a CSV file? What's the format? How are you reading it currently?
0
 
Jack_JonesAuthor Commented:
Plan text files, this fills the listview perfectly. My goal is to eliminate the listview and have it import to a datagridview, so I can eventually build a report from it.

Dim t As String = IO.File.OpenText("C:\Team Links\Inventory\Vehicle\Vehicle Skus.txt").ReadToEnd
        Dim skzInfo() As String = IO.File.ReadAllText("C:\Inventory\Vehicle\Vehicle Skus.txt").Split(vbCrLf)
        Dim InfoDes() As String = IO.File.ReadAllText("C:\Inventory\Vehicle\Vehicle Description.txt").Split(vbCrLf)
        Dim InfoMod() As String = IO.File.ReadAllText("C:\Inventory\Vehicle\Vehicle Atcat.txt").Split(vbCrLf)
        Dim InfoQty() As String = IO.File.ReadAllText("C:\Inventory\Vehicle\Vehicle Number.txt").Split(vbCrLf)
        Dim InfoRTL() As String = IO.File.ReadAllText("C:\Inventory\Vehicle\Vehicle Rtlcost.txt").Split(vbCrLf)

        Try
            For lpz As Integer = 0 To 500
                vehicleSkus.Items.Add(skzInfo(lpz))
                vehicleSkus.Items(lpz).SubItems.Add(InfoDes(lpz))
                vehicleSkus.Items(lpz).SubItems.Add(InfoQty(lpz))
                vehicleSkus.Items(lpz).SubItems.Add(InfoRTL(lpz))
                vehicleSkus.Items(lpz).SubItems.Add(InfoMod(lpz))
            Next
        Catch

        End Try

Open in new window

0
 
CodeCruiserCommented:
You can try

Dim dTable As New DataTable
dTable.Columns.Add("Column1", GetType(String))

Try
            For lpz As Integer = 0 To 500
                Dim drow as DataRow = dTable.NewRow()
                drow(0) = skzInfo(lpz)
                dTable.Rows.Add(drow)
            Next
        Catch
        End Try

DataGridView1.DataSource = dTable
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Jack_JonesAuthor Commented:
How would i have all the colums generated fromt he txt files?
0
 
CodeCruiserCommented:
How are the columns separated? Commas?
0
 
Jack_JonesAuthor Commented:
Each text file just has 1 line of text, I managed to do this but it says the row already exists.

For lpz As Integer = 0 To 500
            Dim drow As DataRow = dTable.NewRow()
            drow(0) = skzInfo(lpz)
            dTable.Rows.Add(drow)
            drow(1) = InfoDes(lpz)
            dTable.Rows.Add(drow)
            drow(2) = InfoQty(lpz)
            dTable.Rows.Add(drow)
            drow(3) = InfoRTL(lpz)
            dTable.Rows.Add(drow)
            drow(4) = InfoMod(lpz)
            dTable.Rows.Add(drow)
        Next lpz

        DataGridView3.DataSource = dTable

Open in new window

0
 
Jack_JonesAuthor Commented:
This row already belongs to this table.  Is the error message after,

 drow(1) = InfoDes(lpz)
            dTable.Rows.Add(drow)
0
 
Jack_JonesAuthor Commented:
Ok figured it out,

 For lpz As Integer = 0 To 500
                Dim drow As DataRow = dTable.NewRow()
                drow(0) = skzInfo(lpz)
                dTable.Rows.Add(drow)
                drow(1) = InfoDes(lpz)
                drow(2) = InfoQty(lpz)
                drow(3) = InfoRTL(lpz)
                drow(4) = InfoMod(lpz)
            Next lpz

Open in new window

0
 
Jack_JonesAuthor Commented:
Thanks again good sir! Next question will be on the way lol!
0
 
CodeCruiserCommented:
Glad to help :-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now