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

editable grids

Status
Not open for further replies.

shabnam

Programmer
Oct 3, 2000
26
0
0
US
Hi,

I need to use an editable grid in my application. As far as I know MSFlexGrid is uneditable. I know that there is a control called Sheridan grid but I don't know the name of the company that produces it. Any ideas - any other grid that I can use?
 
i am having the very same problem. the only solution i came up with, and never implimented for obvious reasons, was to make a big table of lines and text boxes. i made one look good so if all else fails you can use this ugly method

Karl

Karl Pietri
lordhuh.pota.to

 
My problem is that there is a list box with some API names and depending on which one the user selects, the grid has to display its parameters. So the number of columns in the grid depends on the user's selection. Also the user has to be able to enter and I don't want to fiddle with dynamic creation of textboxes at run-time using a control array.
 
If you have not before VB6 ( a VB5 ) then you find on your VB6 CD Profs the DBGrid32.ocx ,he is editable
Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX
Source CodeBook for the programmer
 
Although flexgrids are technically not editable, such behavior can be faked by sizing a textbox over the cell the user clicks on. The text from the textbox can then be entered in the flexgrid programmatically. Check out
!

S
 
shabnam,

You mentioned that your project had a grid that depending on hte user selection the grid would display a different number of columns. Can you give me some additional information on how you did that?

Corinne
 
You are correct, FlexGrid does not allow for direct editing. But there is a workaround to give the appearance of editing. Here is some sample code that you may find useful.

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) & &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
 
Another solution, although I have never used it so don't know how flexible/useful it is, is to use the spreadsheet component of Microsoft Office Web Component. You can modify it to remove the toolbar and title

Grant
 
Apparently, I made a mistake during the copy and paste. The
.Tag assignment line in Public Sub ActivateControl subroutine should read as follows:

rCtl_Control.Tag = Trim(rGrd_grdGrid.Row) & &quot;,&quot; & Trim(rGrd_grdGrid.Col)
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