Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text File -> Grid Control -> Text File

Status
Not open for further replies.

neilkonitzer

Programmer
Jun 27, 2001
168
US
Is there are any sort of grid control that doesn't require the overhead of using ADO? I want to make the size of the installation package as small as possible. In a nutshell, the program reads the contents from a text file (it could be fixed length or csv) into a grid, allow the users to make changes to the data within the grid, and then save the data back into the text file. Thanks in advance.
Neil Konitzer
Freisoft
 
For what you are doing I would read the data into an array and then manually feed the data from the array into the grid. No ADO required. I do this with the MSFlexGrid control. With a little programming you can make it so the user can add, edit and delete information. It is all handled by the array. Thanks and Good Luck!

zemp
 
Thanks for the response. I had looked into using the MSFlexgrid control, but there is no capability to select the contents of the cell for editing. Are you suggesting that I make my own ActiveX control using MSFlexGrid as a base? Neil Konitzer
Freisoft
 
You can do editing by placing a text box over the cell. It sounds fiddly and it is, but once you have it working it's fine. There must be some info on MS. Peter Meachem
peter @ accuflight.com

 
You are correct, FlexGrid does not allow for direct editing. But there is a workaround to give the appearance of editing, along the lines suggested by petermeacham. Here is some sample code that you may find useful. You will need VB6 for this since it uses the Split function in the ResetGridControl routine. If you're using a previous version, then you'll need to write your own split.

There are several steps for this.

1) On your form, first place the Grid (grdGrid). Then on top of the grid, add a TextBox (txtGrid) and a ComboBox (cboGrid)

2) Set the .Visible property of both the combobox and the Textbox to False

In your form, drop in the following three event handlers
Code:
Private Sub grdGrid_Click()

   Select Case grdGrid.Col
      Case 0, 3, 5 ' Columns that need Text Boxes
         ActivateControl txtGrid, grdGrid
      Case 1, 2, 4 ' Columns that need a Combo Box
         <Load the Combo Box with Values>
         ActivateControl cboGrid, grdGrid
      Case Else
         ' Column is not editable
   End Select

End Sub

Private Sub cboGrid_LostFocus()

   ResetSetGrid cboGrid, grdGrid

End Sub

Private Sub txtGrid_LostFocus()

   ResetSetGrid txtGrid, grdGrid

End Sub
Now in a module (or in the same form), drop in the following two public subroutines
Code:
Public Sub ActivateControl(rCtl_Control As Control, rGrd_grdGrid As MSHFlexGrid)

   rCtl_Control.Top = rGrd_grdGrid.Top + rGrd_grdGrid.CellTop - 20
   rCtl_Control.Left = rGrd_grdGrid.Left + rGrd_grdGrid.CellLeft - 20
   rCtl_Control.Tag = Trim(rGrd_grdGrid.Row) & &quot;,&quot; & Trim(rGrd_grdGrid.Col)

' You might want to adjust the following two lines based on your desired look and feel
   rCtl_Control.Width = rGrd_grdGrid.CellWidth
' Cannot Set the Height of a ComboBox
   If (TypeName(rCtl_Control) = &quot;TextBox&quot;) Then
      rCtl_Control.Height = rGrd_grdGrid.CellHeight
   End If

   rCtl_Control.Text = rGrd_grdGrid.Text
   rCtl_Control.Visible = True
   rCtl_Control.Enabled = True
   rCtl_Control.SetFocus

End Sub

Public Sub ResetSetGrid(rCtl_Control As Control, rGrd_grdGrid As MSHFlexGrid)

   Dim PrevPos As Variant

   PrevPos = Split(rCtl_Control.Tag, &quot;,&quot;) ' Tag is format Row,Col
   rGrd_grdGrid.TextMatrix(PrevPos(0), PrevPos(1)) = rCtl_Control.Text
   rCtl_Control.Visible = False

End Sub
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
There is ActiveX collection called &quot;Sheridan&quot;. It has a various types of databind controls as well as data list controls, where you can edit inside the grid itself and you can enter new rows to the grid as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top