Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Highlight and edit a column in msflexgrid - vb6

Posted on 2014-09-17
13
Medium Priority
?
502 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 50

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

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

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 50

Accepted Solution

by:
Martin Liss earned 2000 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 50

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 50

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 50

Expert Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

581 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