Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Editing MSFlexGrid in vb6
Author:
Gaurish Salunke
E-mail:
Click to e-mail author
Submitted:
4/5/2008
Version:
VB6
Compatibility:
VB6
Category:
Controls
Views:
26483
As you all know that by default we cannot write in MSFlexgrid. In order to edit the records in MSFlexgrid we need to explicitly write a code. This is how it works. We drop a text box on the form. Now whenever we click on any of the cells in the grid ,we should move the textbox on that cell such that the textbox fits exactly on the cell. We have to then call the required events to copy the text written in textbox into the cell.
Declarations:
On the form, we have - MSFlexGrid Name : MSFlexGrid1 - TextBox Name : Text2
Code:
Private Sub MSFlexGrid1_Click() Select Case MSFlexGrid1.Col Case 6: chkSelect.Visible = True chkSelect.Left = MSFlexGrid1.Left + MSFlexGrid1.CellLeft chkSelect.Top = MSFlexGrid1.Top + MSFlexGrid1.CellTop If MSFlexGrid1.Text = "Selected" Then chkSelect.Value = "1" Else chkSelect.Value = "0" End If chkSelect.SetFocus chkSelect.Visible = True lrow = MSFlexGrid1.Row lcol = MSFlexGrid1.Col End Select End Sub Private Sub MSFlexGrid1_DblClick() GridEdit Asc(" ") End Sub Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer) GridEdit KeyAscii End Sub Private Sub GridEdit(KeyAscii As Integer) ' Position the TextBox over the cell. Text2.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left Text2.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top Text2.Width = MSFlexGrid1.CellWidth Text2.Height = MSFlexGrid1.CellHeight Text2.Visible = True Text2.SetFocus Select Case KeyAscii Case 0 To Asc(" ") Text2.Text = MSFlexGrid1.Text Text2.SelStart = Len(Text1.Text) Case Else Text2.Text = Chr$(KeyAscii) Text2.SelStart = 1 End Select End Sub Private Sub Text2_KeyDown(KeyCode As Integer, Shift As _ Integer) Select Case KeyCode Case vbKeyEscape ' Leave the text unchanged. Text2.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 Case vbKeyLeft ' Move left 1 col. MSFlexGrid1.SetFocus DoEvents If MSFlexGrid1.Col > MSFlexGrid1.FixedCols Then MSFlexGrid1.Col = MSFlexGrid1.Col - 1 End If Case vbKeyRight ' Move right 1 col. MSFlexGrid1.SetFocus DoEvents If MSFlexGrid1.Col < MSFlexGrid1.Cols - 1 Then MSFlexGrid1.Col = MSFlexGrid1.Col + 1 End If End Select End Sub Private Sub MSFlexGrid1_GotFocus() '' If Text2.Visible Then '' MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = Text2.Text '' Text2.Visible = False '' End If End Sub Private Sub chkSelect_LostFocus() If chkSelect.Value = 1 Then MSFlexGrid1.TextMatrix(lrow, lcol) = "Enabled" Else MSFlexGrid1.TextMatrix(lrow, lcol) = "Disabled" End If chkSelect.Visible = False End Sub Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer) If Text2.Visible Then MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = Text2.Text 'Text2.Visible = False End If End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement