[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 569
  • Last Modified:

Convert 1 of datagridview columns to uppercase

I have a datagridview with several columns. I want to change only 1 of those columns to uppercase.
Sample code would be appreciated.
0
dave_sky
Asked:
dave_sky
1 Solution
 
Om PrakashCommented:
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
        If TypeOf e.Control Is TextBox Then
            DirectCast(e.Control, TextBox).CharacterCasing = CharacterCasing.Upper
        End If
    End Sub
0
 
xav056Commented:
in you gridView Row databound event do the following
change the yourGridView to the name of your gridview and the desiredindex t to an integer value indication the position of the colum you want to change

 Private Sub YourGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles YourGridView.RowDataBound
  If e.Row.RowType = DataControlRowType.DataRow Then   
 e.Row.Cells(DesiredIndex).Text = e.Row.Cells(DesiredIndex).Text.toUpper


        End If

End sub

Open in new window

0
 
EDDYKTCommented:
use LoadingRow event

ie

private void YourGrid_LoadingRow(object sender, System.Windows.Controls.DataGridRowEventArgs e)
{
TextBlock txt = this.YourGrid.Columns[YourRow].GetCellContent(e.Row) as TextBlock;
//txt.Text = set your uppercase text
}
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
dave_skyAuthor Commented:
xav056:

I am getting the errors:
Event RowDataBound cannot be found.
Name 'DataControlRowTyoe isnot declared
0
 
xav056Commented:
is trhis an asp.net application or windows?
0
 
dave_skyAuthor Commented:
Windows

0
 
xav056Commented:
in your form_Load Event
add the following code, replace 2 by the desired column you would like to modify
     For Each r As DataGridViewRow In DataGridView1.Rows
            If Not r.Cells(2).Value Is Nothing Then
                r.Cells(2).Value = r.Cells(2).Value.ToString.ToUpper
            End If


        Next
0
 
dave_skyAuthor Commented:
The code worked ok in BindingNavigatorSaveItem also.
I tried various things to get the text to change on entry with no luck
0
 
dave_skyAuthor Commented:
Thank you!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now