Solved

Highlight and edit a column in msflexgrid - vb6

Posted on 2014-09-17
13
306 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 46

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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

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

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 46

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 46

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 46

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 46

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 46

Expert Comment

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

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net 2008 2 59
passing parameter in sql procedure 9 61
Using "ScreenUpdating" 6 63
Export Data to Different .csv Files 26 104
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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