MSFlexGrid problem

Posted on 2002-03-04
Last Modified: 2010-05-02
HI friends,

    I am developing an application for a school. Here one module is Entering Attendance for the students and Marks for different tests conducted.

Marks Entry: I will select Classcode,Medium and Student Number. The subject for that class will be displayed and the user can enter marks. That all in a grid.
I selected MDFlexGrid. Given query and retrieved subjects and displayed in the grid. But how can i enter marks corr. to the subjects. In the grid any column is not accepting user input.

Is this the right choice to take grid or any other control to be used. Pls, give me the solution.

Question by:mrajanikrishna
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3

Accepted Solution

Z_Beeblebrox earned 50 total points
ID: 6839442

The MSFlexGrid does not inherently support editing. Their is an article on MSDN that explains how to add this functionality.


Expert Comment

ID: 6839474
MSFlexGrid does not editing. you can type text into the MSFlexGrid but the cursor will not be there.
if you want to try pls type the following code in the keypress property of the MSFlexGrid control.

if keyascii= 8 then
   if len(obj.text)>0 then
      obj.text = mid(obj.text,1,len (obj.text)-1)
   end if
   obj.text = obj.text & chr(keyasci)
end if


Expert Comment

ID: 6840403
U cannot use MSFlexGrid to edit or change the value in its cells. Whem u type in the new values, it would not be saved to the database.

Below is my suggestion :

To make this technique work, add a TextBox control to the form and then set its Visible property to False, its MultiLine property to True, and its BorderStyle property to 0-None. These routines cause the phantom TextBox (named txtCellEditor) to appear and disappear as needed:

' These variables keep track of the cell that was active
' when edit mode was entered.
Dim cellRow As Long, cellCol As Long

Sub ShowCellEditor()
    With MSHFlexGrid1
        ' Cancel range selection, if any.
        .RowSel = .Row
        .ColSel = .Col
        ' Move the cell editor into place by making it one pixel smaller
        ' than the current cell.
        txtCellEditor.Move .Left + .CellLeft, .Top + .CellTop, _
            .CellWidth - ScaleX(1, vbPixels, vbTwips), _
            .CellHeight - ScaleY(1, vbPixels, vbTwips)
        ' Transfer the contents of the current cell into the TextBox.
        txtCellEditor.Text = .Text
        ' Move the TextBox in front of the grid.
        txtCellEditor.Visible = True
        ' Remember current coordinates for later.
        cellRow = .Row
        cellCol = .Col
    End With
End Sub

Sub HideCellEditor(Optional Cancel As Boolean)
    ' Hide the TextBox control if necessary.
    If txtCellEditor.Visible Then
        ' If the operation hasn't been canceled, transfer the contents
        ' of the TextBox into the cell that was active.
        If Not Cancel Then
            MSHFlexGrid1.TextMatrix(cellRow, cellCol) = txtCellEditor.Text
        End If
        txtCellEditor.Visible = False
    End If
End Sub


The ShowCellEditor routine can move the TextBox into place, thanks to the grid's CellLeft, CellTop, CellWidth, and CellHeight properties. The next step is to determine when cell editing is activated. In the demonstration program, this happens when the grid is double-clicked or when the user presses an alphanumeric key when the grid has the input focus:

Private Sub MSHFlexGrid1_DblClick()
End Sub

Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
    ' If it's an alphanumeric key, it is passed to the TextBox.
    If KeyAscii >= 32 Then
        txtCellEditor.Text = Chr$(KeyAscii)
        txtCellEditor.SelStart = 1
    End If
End Sub


Edit mode is terminated when the TextBox loses the focus (for example, when the user clicks elsewhere in the grid), or when either the Enter or Esc key is pressed:

Private Sub txtCellEditor_LostFocus()
End Sub

Private Sub txtCellEditor_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case 13
        Case 27
            HideCellEditor True     ' Also cancel the edit.
    End Select
End Sub


PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now


Expert Comment

ID: 6840407
It's similar to the codes provided at that link suggested by Z but I definitely am not copying his answer or anything, just coincidence. It uses textboxes superimposed over the cells to make it look as it belongs to the flexgrid.

Sorry in advance to u guys if u think that I'm trying to "jump the queue" here.


Expert Comment

ID: 6884280
Flexgrid doesn't accept userinput. But u can overcome this using TextMatrix Property. To enter value in the FlexGrid
MSFlexGrid1.TextMatrix(1,1) = "Hello"

The TextMatrix Property is read/write property. All u have to do this pass the x,y co-ords to assign some text.


Expert Comment

ID: 6884282
u said:"In the grid any column is not accepting user input"

If this is ur problem, then following is the answer.

Try this code
Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
With MSFlexGrid1
    .TextMatrix(.Row, .Col) = .TextMatrix(.Row, .Col) & Chr(KeyCode)
End With
End Sub

U can also perform Input validation using Keycode Value like Keycode should be between 48 and 57 for Numeric Inputs and so on.

Expert Comment

ID: 7078720

This question has been locked with a Proposed Answer, and remains open today.  Questions in the LOCKED versus OPEN queue draw little to zero additional attention by Experts.

If the Proposed Answer did not serve your needs, please reject it and comment with an update.  If the Proposed Answer helped you, please accept it to grade and close this question.  If you need help splitting points between multiple experts, please comment here with details so we can help you.

EXPERTS ->  Please guide me here in terms of closing recommendations if the Asker does not respond in 4 days.

Thanks to all,
Moondancer - EE Moderator

Expert Comment

ID: 7079323

As Neo78 stated, the answer I gave is a full answer to the question, and his answer is a variation of mine. The answer kcm76 locked the question with is the same that azhaguraj gave earlier. As a result, if the questioner does not come back then I woulkd recommed giving the points to me, or splitting them between Neo78 and I.


Expert Comment

ID: 7523226
Dear kcm76
I've rejected your proposed answer as Experts Exchange holds an experiment to work without the answer button.

See: <>
Paragraph: Site Update for Wednesday, November 06, 2002

By this rejection the Asker will be notified by mail and hopefully he will take his responsibility to finalize the question or post an additional comment.
The Asker sees a button beside every post which says "Accept This Comment As Answer" (including rejected answers) -- so if he/she thinks yours is the best, you'll be awarded the points and the grade.

EXPERTS: I will return in seven days to close this question.
Please leave your thoughts and recommendations here


Thanks !

Experts Exchange Moderator

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question