Important alert: (current site time 7/16/2013 2:56:12 AM EDT)
 

VB icon

Make MSHFlexGrid Editable without help of any textbox or other control

Email
Submitted on: 1/5/2004 10:05:35 PM
By: Kazi Khalid 
Level: Intermediate
User Rating: By 23 Users
Compatibility: VB 5.0, VB 6.0
Views: 40455
(About the author)
 
     Make MSHFlexGrid Editable without help of any textbox or other control
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Make MSHFlexGrid Editable without help of any textbox or other control
' Description:Make MSHFlexGrid Editable without help of any textbox or other control
' By: Kazi Khalid
'
' Assumes:'Take an MSHFlexgrid name it as msh1
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=50802&lngWId=1'for details.'**************************************

'in the keypress event of msh1 write the following code.
Private Sub msh1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyReturn, vbKeyTab
'move to next cell.
With msh1
If .Col + 1 <= .Cols - 1 Then
.Col = .Col + 1
Else
If .Row + 1 <= .Rows - 1 Then
.Row = .Row + 1
.Col = 0
Else
.Row = 1
.Col = 0
End If
End If
End With
Case vbKeyBack
With msh1
'remove the last character, if any.
If Len(.Text) Then
.Text = Left(.Text, Len(.Text) - 1)
End If
End With
Case Is < 32
Case Else
With msh1
.Text = .Text & Chr(KeyAscii)
End With
End Select
End Sub


Other 14 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
1/5/2004 11:26:50 PM

it works!

***** from me

jomblo keren
(If this comment was disrespectful, please report it.)

 
1/6/2004 1:54:17 AM



can anybody there help me, or just give me an sample program of Pharmacy Sales and Inventory System.
(If this comment was disrespectful, please report it.)

 
1/6/2004 10:49:34 AMWinJewel

Wow, Thanks a lot. I love this. SO SIMPLE AND SO WORKABLE.
(If this comment was disrespectful, please report it.)

 
1/7/2004 3:38:28 AM

It works, but it does not change the database itself. How to do so ?
(If this comment was disrespectful, please report it.)

 
1/7/2004 10:16:27 AMTechni Rei Myoko

why are ppl asking this guy to do code totally unrelated to his program
(If this comment was disrespectful, please report it.)

 
1/8/2004 4:00:39 AMFosters

simple and effective. like it. OOOOO from me.
(If this comment was disrespectful, please report it.)

 
1/10/2004 10:49:20 PMAlpha Binary

Not very impressive, but unique, i must admit.
(If this comment was disrespectful, please report it.)

 
1/12/2004 5:52:22 PMAaron Schulz

It works!
(If this comment was disrespectful, please report it.)

 
1/15/2004 12:49:07 AMKenKnutson

Impressive because it works and doesn't take a lot of code to implement. Less code = Fewer Bugs = Better code. Good job. Silly me, I went and used the Microsoft MSDN example which uses a text box.
(If this comment was disrespectful, please report it.)

 
6/7/2004 4:45:51 AM

It is great!!!!!!
(If this comment was disrespectful, please report it.)

 
6/9/2004 4:25:14 AMJustin Yates

Nice idea
(If this comment was disrespectful, please report it.)

 
6/9/2004 4:58:50 AMJustin Yates

In order to delete a cell you have to backspace all the text, and you can't add vbKeyDelete in your case statement because you are using KeyAscii. So to delete cell just add this:

Private Sub msh1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDelete Then
msh1.Text = vbNullString
End If
End Sub


(If this comment was disrespectful, please report it.)

 
8/11/2004 2:10:58 AM

how would i make the cursor visible?
and also how would i add a combo box?
(If this comment was disrespectful, please report it.)

 
4/7/2005 10:57:12 AMNorm Cook

Also works with MSFlexGrid. Suggest this mod to keep the cursor off the fixed cols:
If .Row + 1 <= .Rows - 1 Then
.Row = .Row + 1
.Col = .FixedCols
Else
.Row = 1
.Col = .FixedCols
End If

(If this comment was disrespectful, please report it.)

 
4/7/2005 3:54:08 PMl_c

old idea but still nice

as far as remember dont have the cursor - createcaret api and goodbye simple code.
(If this comment was disrespectful, please report it.)

 
7/19/2008 3:48:03 AM

nice
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.