Click to See Complete Forum and Search --> : VB 6 - Flex Grid


angelis
September 6th, 2001, 10:12 AM
Hi, if anyone can help me,
* how can I extract a value from a selected cell
* how can I edit information from a selected cell in the flex grid
* and finally, how can I transfer a selected row data from a flex grid into another flex grid using a command button i have created for it?

berta
September 6th, 2001, 10:18 AM
1)

myflxgrid.col=1
mtflxgrid.col=1
debug.print mtflxgrid.value

2)

myflxgrid.col=1
mtflxgrid.col=1
mtflxgrid.value="test"

3) ...i don't undestand




<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>

Iouri
September 6th, 2001, 10:22 AM
* how can I extract a value from a selected cell
Value = msfg.TextMatrix(Row,Col)

* how can I edit information from a selected cell in the flex grid
you cannot edit a cell directly. You can add textbox and/or combobox and when
you want to edit the info, position textbox over a cell and enter info there

Option Explicit

Private Sub EndEdit()
'--------------------------
If Combo1.Visible Then
MSFlexGrid1.Text = Combo1.Text
Combo1.Visible = False
ElseIf Text1.Visible Then
MSFlexGrid1.Text = Text1.Text
Text1.Visible = False
End If
End Sub

Private Sub StartEdit()
'--------------------------
If MSFlexGrid1.Col = 2 Then
Combo1.Clear
Combo1.AddItem "Paranoia City"
Combo1.AddItem "Langonsville"
Combo1.AddItem "Codertown"
Combo1.AddItem "Bugvanna"
Combo1.AddItem "Abend"
On Error Resume Next
Combo1.Text = MSFlexGrid1.Text
On Error GoTo 0

GridEditCombo
ElseIf MSFlexGrid1.Col = 3 Then
Combo1.Clear
Combo1.AddItem "CA"
Combo1.AddItem "VT"
Combo1.AddItem "MN"
Combo1.AddItem "WY"
Combo1.AddItem "TX"
On Error Resume Next
Combo1.Text = MSFlexGrid1.Text
On Error GoTo 0

GridEditCombo
Else
GridEditText Asc(" ")
End If
End Sub

' Make the change.
Private Sub Combo1_Click()
'--------------------------
MSFlexGrid1.SetFocus
End Sub


Private Sub Form_Load()
'--------------------------
Dim r As Integer
Dim c As Integer
Dim max_len As Single
Dim new_len As Single

' Use no border.
Text1.BorderStyle = vbBSNone

' Make the grid's cell height match
' that of the ComboBox.
MSFlexGrid1.RowHeightMin = Combo1.Height

' Match the grid's font.
Text1.FontName = MSFlexGrid1.FontName
Text1.FontSize = MSFlexGrid1.FontSize
Text1.Visible = False
Combo1.FontName = MSFlexGrid1.FontName
Combo1.FontSize = MSFlexGrid1.FontSize
Combo1.Visible = False

' Create some data.
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.Cols = 5
MSFlexGrid1.FixedRows = 1
MSFlexGrid1.Rows = 6

MSFlexGrid1.TextMatrix(0, 0) = "Name"
MSFlexGrid1.TextMatrix(0, 1) = "Street"
MSFlexGrid1.TextMatrix(0, 2) = "City"
MSFlexGrid1.TextMatrix(0, 3) = "State"
MSFlexGrid1.TextMatrix(0, 4) = "Zip"

MSFlexGrid1.TextMatrix(1, 0) = "Andy Avaricious"
MSFlexGrid1.TextMatrix(1, 1) = "827 Problem Blvd"
MSFlexGrid1.TextMatrix(1, 2) = "Paranoia City"
MSFlexGrid1.TextMatrix(1, 3) = "CA"
MSFlexGrid1.TextMatrix(1, 4) = "98765"

MSFlexGrid1.TextMatrix(2, 0) = "Betty Boisterous"
MSFlexGrid1.TextMatrix(2, 1) = "4352 Main St Apt 254"
MSFlexGrid1.TextMatrix(2, 2) = "Langonsville"
MSFlexGrid1.TextMatrix(2, 3) = "VT"
MSFlexGrid1.TextMatrix(2, 4) = "01234"

MSFlexGrid1.TextMatrix(3, 0) = "Charles Cheerful"
MSFlexGrid1.TextMatrix(3, 1) = "89 North A Ln"
MSFlexGrid1.TextMatrix(3, 2) = "Codertown"
MSFlexGrid1.TextMatrix(3, 3) = "MN"
MSFlexGrid1.TextMatrix(3, 4) = "54583"

MSFlexGrid1.TextMatrix(4, 0) = "Denise Delightful"
MSFlexGrid1.TextMatrix(4, 1) = "89 75th"
MSFlexGrid1.TextMatrix(4, 2) = "Bugvanna"
MSFlexGrid1.TextMatrix(4, 3) = "WY"
MSFlexGrid1.TextMatrix(4, 4) = "82738"

MSFlexGrid1.TextMatrix(5, 0) = "Ed Enlightened"
MSFlexGrid1.TextMatrix(5, 1) = "2765 N South St E"
MSFlexGrid1.TextMatrix(5, 2) = "Abend"
MSFlexGrid1.TextMatrix(5, 3) = "TX"
MSFlexGrid1.TextMatrix(5, 4) = "67583"

' Size the columns.
Font.Name = MSFlexGrid1.Font.Name
Font.Size = MSFlexGrid1.Font.Size
For c = 0 To MSFlexGrid1.Cols - 1
max_len = 0
For r = 0 To MSFlexGrid1.Rows - 1
new_len = TextWidth(MSFlexGrid1.TextMatrix(r, c))
If max_len < new_len Then max_len = new_len
Next r
MSFlexGrid1.ColWidth(c) = max_len + 240
MSFlexGrid1.ColAlignment(c) = flexAlignLeftCenter
Next c

MSFlexGrid1.AllowUserResizing = flexResizeBoth
End Sub

Private Sub GridEditText(ByVal KeyAscii As Integer)
'--------------------------
' Position the TextBox over the cell.
Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left
Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top
Text1.Width = MSFlexGrid1.CellWidth
Text1.Height = MSFlexGrid1.CellHeight
Text1.Visible = True
Text1.SetFocus

Select Case KeyAscii
Case 0 To Asc(" ")
Text1.Text = MSFlexGrid1.Text
Text1.SelStart = Len(Text1.Text)
Case Else
Text1.Text = Chr$(KeyAscii)
Text1.SelStart = 1
End Select
End Sub

Private Sub GridEditCombo()
'--------------------------
' Position the ComboBox over the cell.
Combo1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left
Combo1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top
Combo1.Width = MSFlexGrid1.CellWidth
Combo1.Visible = True
Combo1.SetFocus
End Sub
Private Sub Form_Resize()
MSFlexGrid1.Move 0, 0, ScaleWidth, ScaleHeight
End Sub


Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
'--------------------------
Select Case KeyCode
Case vbKeyEscape
' Leave the text unchanged.
Text1.Visible = False
MSFlexGrid1.SetFocus

Case vbKeyReturn
' Finish editing.
MSFlexGrid1.SetFocus

Case vbKeyDown
' Move down 1 row.
MSFlexGrid1.SetFocus
DoEvents
If MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 Then
MSFlexGrid1.Row = MSFlexGrid1.Row + 1
End If

Case vbKeyUp
' Move up 1 row.
MSFlexGrid1.SetFocus
DoEvents
If MSFlexGrid1.Row > MSFlexGrid1.FixedRows Then
MSFlexGrid1.Row = MSFlexGrid1.Row - 1
End If

End Select
End Sub
' Do not beep on Return or Escape.

Private Sub Text1_KeyPress(KeyAscii As Integer)
'--------------------------
If (KeyAscii = vbKeyReturn) Or _
(KeyAscii = vbKeyEscape) _
Then KeyAscii = 0
End Sub

Private Sub MSFlexGrid1_DblClick()
'--------------------------
StartEdit
End Sub

Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
'--------------------------
If MSFlexGrid1.Col <> 2 And _
MSFlexGrid1.Col <> 3 _
Then
GridEditText KeyAscii
End If
End Sub

Private Sub MSFlexGrid1_LeaveCell()
'--------------------------
EndEdit
End Sub

Private Sub MSFlexGrid1_GotFocus()
'--------------------------
EndEdit
End Sub

* and finally, how can I transfer a selected row data from a flex grid into another flex grid using a command button i have created
for Row = 1 to 5
for Col = 1 to 3
msfg2.TextMatrix(Row,Col)=msfg1.TextMatrix(Row,Col)
next Col
next Row

Iouri Boutchkine
iouri@hotsheet.com

angelis
September 6th, 2001, 10:55 AM
thanks for you help, but do I have to give a row number and column number?
It's just that the flex grid loads up automatically with records from a recordset, so how exactly is it going to be able to know which row has been selected? so that the record can be removed from there and added into another flex grid (it has to transfer all five fields)?
Thank once again, I much appreciate it

angelis
September 6th, 2001, 10:55 AM
thanks for you help, but do I have to give a row number and column number?
It's just that the flex grid loads up automatically with records from a recordset, so how exactly is it going to be able to know which row has been selected? so that the record can be removed from there and added into another flex grid (it has to transfer all five fields)?
Thanks once again, I appreciated it

Iouri
September 6th, 2001, 02:00 PM
Instead Row and Col you have to give row and col number. Look at the bootom part of the answer and you will see.

Iouri Boutchkine
iouri@hotsheet.com