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

edit/update flexgrid fields

Status
Not open for further replies.

djaypee

Programmer
Nov 30, 2001
3
BE
how do i edit and/or update the fields of a MSFlexGrid in VB ?

thanx in advance,

djaypee
 
One way to handle the typing into the cells of a flexgrid is via the use of an edit box. Create a text box (txtGrid) on the form, and set the visible property to false.

Activate and position the text box when you click in the grid:

Private Sub grdGrid_Click()

Dim lInt_Left as Integer
Dim lInt_Top as Integer
Dim lInt_RowID as Integer
Dim lInt_ColId as Integer

' Keep Track of Which Row and Col

lInt_RowID = grdGrid.Row
lInt_ColID = grdGrid.Col

' Get Coordinates of this Cell

lInt_Left = grdGrid.Left + grdGrid.CellLeft
lInt_Top = grdGrid.Top + grdGrid.CellTop

' Position the edit box over the cell

txtGrid.Top = lInt_Top - 20
txtGrid.Left = lInt_Left - 20
txtGrid.Height = grdGrid.RowHeight(lInt_RowID)
txtGrid.Width = grdGrid.CellWidth

' Store in the Tab the Row and Col being Updated

txtGrid.Tag = lInt_RowID & "," & lInt_ColID

' Bring Current Value into text box

txtGrid.Text = grdGrid.Text

' Activate the text box

txtGrid.Visible = True
txtGrid.Enabled = True
txtGrid.SetFocus

End Sub

The in the lost focus of the text box - copy the data into the grid and hide the text box


Private Sub txtGrid_LostFocus()

Dim lVar_PrevPos_Arr As Variant
Dim lInt_RowID As Integer
Dim lInt_ColID As Integer

' Get the Grid Cell Row and Col from the Tag Field

lVar_PrevPos_Arr = Split(edGrid.Tag, ",")
lInt_RowID = pVar_PrevPos_Arr(1)
lInt_ColID = pVar_PrevPos_Arr(2)

' Copy the TextBox into the Grid

grdGrid.TextMatrix(lInt_RowID, lInt_ColID) = txtGrid.Text

' Hide the text box

txtGrid.Visible = False

End Sub

This should get you started. You can use this same technique with combo boxes as well
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Depending on how eligant you want to get, you can also use an input box. I do this in the flexgrid's enter cell event.

kinda like this:

private sub flexgrid_EnterCell()
dim strString as string

strSring = inputbox("Please enter something")
'put some string editing stuff here like isnumeric, isdate, 'or if it is blank.
'if all is well set the flexgrid textmatrix property to the 'value of string (strString)
flexgrid.textmatrix(flexgrid.row, flexgrid.col) = strString

end sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top