Solved

Highlight and edit a column in msflexgrid - vb6

Posted on 2014-09-17
13
283 Views
Last Modified: 2014-09-18
This is what I am using to edit only one column in my flexgrid.  column 10

Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)

Dim sTemp As String

With MSFlexGrid1

sTemp = .TextMatrix(.Row, .Col)

If .Col <> 10 Then Exit Sub ' This might need to be 7
Select Case KeyAscii
Case 8 ' backspace
If Len(sTemp) > 0 Then
sTemp = Left$(sTemp, Len(sTemp) - 1)
End If
Case 27 ' escape
sTemp = ""
Case 0 To 31
KeyAscii = 0
Case Else
sTemp = sTemp & Chr$(KeyAscii)
End Select
.TextMatrix(.Row, .Col) = sTemp
End With

End Sub

Open in new window


The problem is that when I edit the column it begins at the far right of the data and then I have to delete each character one at a time in order to edit or replace the data.  Can I not be able to just simply highlight a specific word or portion and then just edit like I do in a word document?  How can I edit values simply by highlighting and editing?
0
Comment
Question by:al4629740
  • 7
  • 6
13 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40329543
Here is a demo project that floats a textbox over the grid cells. It should help you do what you want. Note that the green color is just there for emphasis.
Project1.zip
0
 

Author Comment

by:al4629740
ID: 40329602
I like it.

Is that the only way to do it?
0
 

Author Comment

by:al4629740
ID: 40329607
In your example you use an MSHFlexgrid but I use an MSFlexgrid.  Are they basically the same?
0
 

Author Comment

by:al4629740
ID: 40329608
Also, how do I restrict the textbox to be used only on column 10?
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40329609
I can't think of any other way.
0
 

Author Comment

by:al4629740
ID: 40329645
How do I restrict it only to work in col 10
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 45

Expert Comment

by:Martin Liss
ID: 40329667
I'm about to go to sleep so I'll get back to you in the morning.
0
 

Author Comment

by:al4629740
ID: 40330153
Ok
0
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40330411
Add lines 6 through 9.

Sub MSFlexGridEdit(MSFlexGrid As Control, Edt As Control, KeyAscii As Integer)

    ' This only happens for the 1st character entered.
    ' The other characters are typed into txtEdit.
    
    ' Restrict the editing to the 10th column
    If MSFlexGrid.Col <> 9 Then
        Exit Sub
    End If
    
    ' Use the character that was typed.
    Select Case KeyAscii

    ' A space means edit the current text.
    Case 0 To 32
        Edt = MSFlexGrid
        Edt.SelStart = 1000

    ' Anything else means replace the current text.
    Case Else
        Edt = Chr(KeyAscii)
        Edt.SelStart = 1
    End Select

    ' Show Edt at the right place.
    Edt.Move grdFloat.Left + MSFlexGrid.CellLeft, MSFlexGrid.CellTop + MSFlexGrid.Top, _
        MSFlexGrid.CellWidth, MSFlexGrid.CellHeight
     
    Edt.Visible = True

    ' Initially set the text value to whatever is in the cell
    If Edt.Text = "" Then
        Edt.Text = MSFlexGrid.Text
    End If

    ' And let it work.
    Edt.SetFocus
End Sub

Open in new window

0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40330662
I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0
 

Author Comment

by:al4629740
ID: 40330901
Is it possible to modify this code to simply view a paragraph within a cell.  Without allowing the user to edit the cell?  I asked another open question....
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40330911
Is it possible to modify this code to simply view a paragraph within a cell
Yes but you should ask a new question for that.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40330913
Never mind, I see the new question.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

744 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

13 Experts available now in Live!

Get 1:1 Help Now