Solved

MSFlexGrid problem

Posted on 2002-03-04
9
169 Views
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.

0
Comment
Question by:mrajanikrishna
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 7

Accepted Solution

by:
Z_Beeblebrox earned 50 total points
ID: 6839442
Hi,

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

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconeditingcellsinhflexsprdsht.asp

Zaphod.
0
 

Expert Comment

by:azhaguraj
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
else
   obj.text = obj.text & chr(keyasci)
end if
 

       
0
 
LVL 1

Expert Comment

by:Neo78
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
        txtCellEditor.ZOrder
        txtCellEditor.SetFocus
        ' 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()
    ShowCellEditor
End Sub

Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
    ShowCellEditor
    ' 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()
    HideCellEditor
End Sub

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

Regards.

0
 
LVL 1

Expert Comment

by:Neo78
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.

Regards.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 5

Expert Comment

by:kcm76
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.

Regards
KCM
0
 
LVL 5

Expert Comment

by:kcm76
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.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7078720
Greetings.

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
0
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 7079323
Hi,

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.

Zaphod.
0
 
LVL 1

Expert Comment

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

See: <http://www.experts-exchange.com/jsp/communityNews.jsp>
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

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Thanks !

kodiakbear
Experts Exchange Moderator
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now