Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. datagrid and text files

datagrid and text files

Scheduled Pinned Locked Moved Visual Basic
question
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Silver Grey
    wrote on last edited by
    #1

    I would like to build a datagrid from a directory of text files. How do I get the files from the directory into the datagrid? Thank you, Silver-grey

    silver-gray

    D 1 Reply Last reply
    0
    • S Silver Grey

      I would like to build a datagrid from a directory of text files. How do I get the files from the directory into the datagrid? Thank you, Silver-grey

      silver-gray

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Why would you want to use such a heavy-weight control to display a list of filenames?

      Dave Kreskowiak Microsoft MVP - Visual Basic

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Why would you want to use such a heavy-weight control to display a list of filenames?

        Dave Kreskowiak Microsoft MVP - Visual Basic

        S Offline
        S Offline
        Silver Grey
        wrote on last edited by
        #3

        Because that is the User Specs. If you don't know a way to get the files in the directory and write them to another file name, Please don't comment. I thought that this was to help!! with the question:

        silver-gray

        D 1 Reply Last reply
        0
        • S Silver Grey

          Because that is the User Specs. If you don't know a way to get the files in the directory and write them to another file name, Please don't comment. I thought that this was to help!! with the question:

          silver-gray

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Silver-Grey wrote:

          If you don't know a way to get the files in the directory and write them to another file name, Please don't comment.

          OK, smart-ass...I just thought I would find out why the heavy wieght control needs to be used before I put the effort into commenting. Normally, a ListView is used for showing a list of filenames. Using a DataGrid for this is pretty odd, customer spec or no. I thought, "maybe this guy is a noobie and doesn't know any better. Let's find out first..." Well, here's one way to do it...

          Dim files As String() = Directory.GetFiles(directoryPath)
          DataGridView1.Columns.Add( New DataGridViewTextBoxColumn() )
          For Each f As String in files
          Dim fa As String() = {f}
          DataGridView1.Rows.Add(fa)
          Next

          This is probably not the best way to do it, but hey. I work out the specs with the customer and don't let them make the mistake of dictating them to me. You're supposed to work with the customer to come up with a proper solution, not for the customer.

          Dave Kreskowiak Microsoft MVP - Visual Basic

          S 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Silver-Grey wrote:

            If you don't know a way to get the files in the directory and write them to another file name, Please don't comment.

            OK, smart-ass...I just thought I would find out why the heavy wieght control needs to be used before I put the effort into commenting. Normally, a ListView is used for showing a list of filenames. Using a DataGrid for this is pretty odd, customer spec or no. I thought, "maybe this guy is a noobie and doesn't know any better. Let's find out first..." Well, here's one way to do it...

            Dim files As String() = Directory.GetFiles(directoryPath)
            DataGridView1.Columns.Add( New DataGridViewTextBoxColumn() )
            For Each f As String in files
            Dim fa As String() = {f}
            DataGridView1.Rows.Add(fa)
            Next

            This is probably not the best way to do it, but hey. I work out the specs with the customer and don't let them make the mistake of dictating them to me. You're supposed to work with the customer to come up with a proper solution, not for the customer.

            Dave Kreskowiak Microsoft MVP - Visual Basic

            S Offline
            S Offline
            Silver Grey
            wrote on last edited by
            #5

            I don't have a datagridview in tool box. Using 2003 Visual Studio

            silver-gray

            D 1 Reply Last reply
            0
            • S Silver Grey

              I don't have a datagridview in tool box. Using 2003 Visual Studio

              silver-gray

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Great! More stuff I'm supposed to know without you explaining... Let's see, my old .NET 1.x DataGrid is a bit rusty, but...

              Dim files As String() = Directory.GetFiles(directoryPath)
              Dim fa As New ArrayList()
              fa.AddRange(files)
              DataGrid1.DataSource = fa

              Dave Kreskowiak Microsoft MVP - Visual Basic

              S 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Great! More stuff I'm supposed to know without you explaining... Let's see, my old .NET 1.x DataGrid is a bit rusty, but...

                Dim files As String() = Directory.GetFiles(directoryPath)
                Dim fa As New ArrayList()
                fa.AddRange(files)
                DataGrid1.DataSource = fa

                Dave Kreskowiak Microsoft MVP - Visual Basic

                S Offline
                S Offline
                Silver Grey
                wrote on last edited by
                #7

                That didn't work. I guess I will have to use a listbox. I can get data inti it. Now trying to select data out of it and write a new file with a different name. Silver-grey

                silver-gray

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups