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

support direct entry to cells in MSFlexgrid

Status
Not open for further replies.

ebeesam

Programmer
Jan 23, 2003
7
0
0
IN
i am working in VB6 and sqlserver2000

i wannt to edit msflex means Should support direct entry to cells. is any hope for msflex grid and any chance

pls reply me
Thanks,
Ebee Sam
 
The Microsoft FlexGrid (MSFlexGrid) control displays and operates on tabular data. It allows complete flexibility to sort, merge, and format tables containing strings and pictures. When bound to a Data control, MSFlexGrid displays read-only data.

Transcend
[gorgeous]
 
You can program it if know how to use TextMatrix, Row, Col property of MSFlex grid. You will also require the help of textbox for editing.
 
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


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


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.Row) & &quot;,&quot; & Trim(rGrd_grdGrid.Col)
rCtl_Control.Width = IIf(rGrd_grdGrid.CellWidth < 1200, 1200, 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 Integer

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
 
Search this forum for 'MSFlexGrid' and/or 'Floating textbox' and you should find other threads on the subject. Thanks and Good Luck!

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top