VB/Office Forums  

Go Back   VB/Office Forums > .NET/Office Programming > VB.NET

VB.NET Questions on programming all versions of VB.NET (2002, 2003, 2005, 2008 & 2010 etc.)


Reply
 
Thread Tools Display Modes
  #1  
Old November 24th, 2008, 06:52 AM
Static Static is offline
n00b Member
 
Join Date: Nov 2008
Posts: 20
Thumbs up [RESOLVED] DataGridView KeyPress Convert to UCASE

how do I make it so when they type something in a certain column to changes it to upper case?

it seems like only some keys fire the keypress!??

Code:
Private Sub DG1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DG1.KeyPress
        If DG1.SelectedCells(0).ColumnIndex = cRow Then e.KeyChar = UCase(Asc(e.KeyChar))
    End Sub

Last edited by Static; November 24th, 2008 at 10:39 AM.
Reply With Quote
  #2  
Old November 24th, 2008, 10:32 AM
ProphetBeal's Avatar
ProphetBeal ProphetBeal is offline
Super Moderator
Your Banned!
 
Join Date: Nov 2008
Location: New York
Posts: 20
Re: DataGridView KeyPress Convert to UCASE

From what I've seen the KeyPress event in DataGrids can be tricky. The way I've gotten around this was by using the Validated event to capitalize the whole cell instead of each letter.

Code:
Private Sub DataGridView1_CellValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValidated
    If (e.RowIndex >= 0) And (e.ColumnIndex >= 0) AndAlso (TypeOf DirectCast(sender, DataGridView).Item(e.ColumnIndex, e.RowIndex).Value Is String) Then
      DirectCast(sender, DataGridView).Item(e.ColumnIndex, e.RowIndex).Value = CType(DirectCast(sender, DataGridView).Item(e.ColumnIndex, e.RowIndex).Value, String).ToUpper
    End If      
  End Sub
Reply With Quote
  #3  
Old November 24th, 2008, 10:38 AM
Static Static is offline
n00b Member
 
Join Date: Nov 2008
Posts: 20
Re: DataGridView KeyPress Convert to UCASE

perfect! thanks
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -7. The time now is 10:52 PM.


vBulletin skins developed by: RobDog888

Copyright © 2007-2009 by YodaMedia™. All Rights reserved.

All trademarks referenced on this site are the property of their respective owners.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.