Populate a DBGrid via a text file

I need to populate a dbgrid using a text delimitted file. Also the users must be able to edit the grid and therefore edit the text file.
I am copying or recreating a program where my client lost the source code. The previous developer was populating a grid using a text file. But now my client also wants to be able to edit the values in the grid



Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I can suggest using an uprated MSFlexGrid called axgrid. The latter is effectively an MSFlexGrid that allows you to edit the grid. It is not a DBGrid, but the editing is enough to make it useful.

As for getting the textfile in, if the delimiters are tabs, then it is simply a matter of reading the file line by line as follows :

F = FreeFile
Open "c:\whereisit.txt" For Input AS #F
While Not F.EOF
  Line Input #F,Tmp
  Grid1.AddItem Tmp
Close #F

To update the text file, you'll need to write the entire file.

To locate axgrid, just search for it on the net. If you can't find it, let me know so that I can upload it to some or other server.

The suggested solution is not ideal (a DBGrid operating on a textfile would be nicer), but if no one answers or your client is breathing down your neck, give it a bash.
How about importing the grid to a db then editting it using a grid, export back to text file.
Éric MoreauSenior .Net ConsultantCommented:
Just an idea but it is worth trying!

Populate an in-memory ADO recordset and bind it to a DataGrid control. Then place a button that will recreate the delimitted text file from the recordset!
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

How about using ODBC Text driver best for UR case I believe
Look, DBGrid means DataBaseGrid, not TextGrid.  you can make your own grid control via text box control arays.
CraigLazarAuthor Commented:
Thanx but idecided to use a dbgrid and rather populate it from an access database, now just gotta see if the client is happy with it

thanx for all the input though

Here's some code to be able to edit a grid, (just in case you need it)

Private Sub GridProps_DblClick()
    Dim RowCounter          As Integer
    Dim Offset              As Single
    Dim RowOfInterest       As Integer
    Dim TmpBtn              As CommandButton
    For Each TmpBtn In BtnQuit
        TmpBtn.Enabled = False
    tbsOptions.Enabled = False
    With GridProps
        .Enabled = False
        RowOfInterest = .Row
        For RowCounter = 0 To RowOfInterest - 1
            If .RowIsVisible(RowCounter) Then
                Offset = Offset + .RowHeight(RowCounter) + 15 'gridlines
            End If
        txtEdit.Move .Left + (.Width / 2), .Top + Offset, (.Width / 2), .RowHeight(RowOfInterest)
        txtEdit.Text = .Text
        txtEdit.Visible = True
        txtEditKotteke.ZOrder vbBringToFront
        .Col = 1
    End With

End Sub


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.