Shan77
April 25th, 2001, 08:29 PM
How do I allow user input into the MS Flex Grid cells ??
Help appreciated.
Help appreciated.
|
Click to See Complete Forum and Search --> : Allowing user input into MS Flex Grid cells Shan77 April 25th, 2001, 08:29 PM How do I allow user input into the MS Flex Grid cells ?? Help appreciated. daneb April 26th, 2001, 03:51 AM Hi. I have read in a book that during design-time, you can place a textbox anywhere on your form. Make this textbox invisible. Then at run-time, you can show this textbox and position it above the cell that you clicked for input. The effect is it will be like you are inputting in the grid's cell. After input, you put the contents of the textbox in the cell and hide the textbox again. The events of the flexgrid that you can use are the EnterCell and LeaveCell events. SAKYA April 26th, 2001, 06:03 AM MSflexgrid does not allow direct userinput .butyou can use a text box to do it.i did this long ago.i will give you the steps. take a text box. set it's visible property to false and borderstyle property to none.in the Form_load event set the width and height property of the textbox equal to the cellwidth and cell height property of the grid control.now on the entercell event set the left and top properties of the text box equal to the cellleft and celltop properties of the grid control.make the textbox visible.now on the leavecell event set the text propery of the grid control equal to the text property of the text box.make the textbox invisible.you can add more code to make it look better.let me know if it helps you shree April 26th, 2001, 07:28 AM The MSFlexGrid doesn't inherently allow you to edit data in a cell. Here is the code that illustrates a workaround, using a textbox. Place a textbox on a form and set the following properties Appearance = 0 'Flat BorderStyle = 0 'None Height = 375 Left = 1560 TabIndex = 1 Text Top = 240 Width = 1455 And a MSFlexGrid control with the following properties Height = 2895 Left = 600 TabIndex = 0 Top = 720 Width = 4215 Rows = 5 Cols = 5 Now paste the following code into the form private Sub MSFlexGrid1_DblClick() GridEdit Asc(" ") End Sub private Sub MSFlexGrid1_KeyPress(KeyAscii as Integer) GridEdit KeyAscii End Sub Sub GridEdit(KeyAscii as Integer) 'use correct font Text1.FontName = MSFlexGrid1.FontName Text1.FontSize = MSFlexGrid1.FontSize Select Case KeyAscii Case 0 to Asc(" ") Text1 = MSFlexGrid1 Text1.SelStart = 1000 Case else Text1 = Chr(KeyAscii) Text1.SelStart = 1 End Select 'position the edit box 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 End Sub private Sub MSFlexGrid1_LeaveCell() If Text1.Visible then MSFlexGrid1 = Text1 Text1.Visible = false End If End Sub private Sub MSFlexGrid1_GotFocus() If Text1.Visible then MSFlexGrid1 = Text1 Text1.Visible = false End If End Sub private Sub Text1_KeyDown(KeyCode as Integer, Shift as Integer) Select Case KeyCode Case vbKeyEscape Text1.Visible = false MSFlexGrid1.SetFocus Case vbKeyReturn MSFlexGrid1.SetFocus Case vbKeyDown MSFlexGrid1.SetFocus DoEvents If MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 then MSFlexGrid1.Row = MSFlexGrid1.Row + 1 End If Case vbKeyUp MSFlexGrid1.SetFocus DoEvents If MSFlexGrid1.Row > MSFlexGrid1.FixedRows then MSFlexGrid1.Row = MSFlexGrid1.Row - 1 End If End Select End Sub private Sub Text1_KeyPress(KeyAscii as Integer) If KeyAscii = vbKeyReturn then KeyAscii = 0 End Sub rahim_rasimin May 28th, 2001, 11:04 PM Input to MSFlexGrid =================== It is possible to input on flexigrid. Try double click your MSFlexgird, you will find event Grid_KeyPress and Grid_KeyDown: Grid_KeyDown(KeyCode As Integer, Shift As Integer) Grid_KeyPress(KeyAscii As Integer) You can manipulate KeyCode, KeyAscii, and Shift to accpet/control your input. Please refer to ASCII character representation from VB help to know the detail. How to accept input? The keycode/keyascii represent the character input from keyboard, convert it into character using function chr(KeyAscii) or chr(KeyCode). Mail to me if you want the code example: rahim_rasimin@yahoo.com Good luck John G Duffy May 29th, 2001, 09:40 AM Where did you get your MSFlexGrid from? The one I got when I installed VB 6.0 PRO does not have those events you described. Could the be from a Addon product? John G Share2 May 29th, 2001, 11:54 PM You can go to http://www.share2.com/easygrid/ to download a substitute OCX. It's powerful and meets any requirements. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |