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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Grid Problem

Status
Not open for further replies.

Monguse

Programmer
Mar 11, 2002
63
US
I have a program that links to an Access Database, one table contains a list of dates for "Week Of" and a "Shipping Date"
and 3 other fields. If I place a Data Grid on a form and run the program I can see all the data in the table, but no matter what changes I've tried With the properties, I am not able to edit any of the information in the table. This table needs to be updates from time to time and it is a pain to open Access to do so, and besides I don't really want just anyone in the d/b.

The project uses ADO to connect to the database.
Any Ideas? or more info needed? Let me know thanks "The beauty of the second amendment is, that it will not be needed until they try to take it." - Thomas Jefferson

WebMaster:
 
If you're using a FlexGrid as the DataGrid, then unfortunately, the FlexGrid does not allow for direct editing. But there is a workaround. 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


3) In your form, drop in the following three event handlers

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


4) Now in a module (or in the same form), drop in the following two public subroutines

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) & &quot;,&quot; & Trim(rGrd_grdGrid)
I usually prefer a minimum width (1800) for the control, otherwise go as wide as that column
rCtl_Control.Width = IIf((rGrd_grdGrid.CellWidth < 1800), 1800, rGrd_grdGrid.CellWidth)
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;)
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top