Solved

Highlight and edit a column in msflexgrid - vb6

Posted on 2014-09-17
13
353 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
[X]
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
  • 7
  • 6
13 Comments
 
LVL 47

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
Industry Leaders: 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 47

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 47

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 47

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 47

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 47

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 47

Expert Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

732 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