Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6605013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:13:58+00:00 2026-05-25T19:13:58+00:00

I have added TextBox control inside the grid: I want my DataGridView TextBox column

  • 0

I have added TextBox control inside the grid: I want my DataGridView TextBox column to hold numbers without any decimal values. How can I do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:13:58+00:00Added an answer on May 25, 2026 at 7:13 pm

    From: http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/919b059c-dba9-40d2-bac7-608a9b120336

    You can handle the DataGridView.EditingControlShowing event to cast
    the editing control to TextBox when editing in the column you want to
    restrict input on, and attach KeyPress event to the TextBox, in the
    KeyPress event handler function, we can call the char.IsNumber()
    method to restrict the key board input, something like this:

    private void Form1_Load(object sender, EventArgs e)
    {
       DataTable dt = new DataTable();
       dt.Columns.Add("c1", typeof(int));
       dt.Columns.Add("c2");
       for (int j = 0; j < 10; j++)
       {
          dt.Rows.Add(j, "aaa" + j.ToString());
       }
    
       this.dataGridView1.DataSource = dt;
       this.dataGridView1.EditingControlShowing +=
          new DataGridViewEditingControlShowingEventHandler(
             dataGridView1_EditingControlShowing);
    }
    
    private bool IsHandleAdded;
    
    void dataGridView1_EditingControlShowing(object sender,
        DataGridViewEditingControlShowingEventArgs e)
    {
       if (!IsHandleAdded &&
           this.dataGridView1.CurrentCell.ColumnIndex == 0)
       {
          TextBox tx = e.Control as TextBox;
          if (tx != null)
          {
             tx.KeyPress += new KeyPressEventHandler(tx_KeyPress);
             this.IsHandleAdded = true;
          }
       }
    }
    
    void tx_KeyPress(object sender, KeyPressEventArgs e)
    {
       if (!(char.IsNumber(e.KeyChar) || e.KeyChar == '\b'))
       {
          e.Handled = true;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a control and added a TextBox inside that control, I am
I have custom control with asp textbox inside. And i need to Validate by
I have created a silverlight 5 project and added a textbox control to a
I have a textbox without calendar control and we will call it as publication
I've recently added the JQuery autocomplete plug in and have a textbox that autocompletes
I have added some dynamic textboxes upon a button click. I need the values
I have added a parameter to my report with the option Allow Multiple Values
I have a user control that allows items to be added to it by
I have added a textbox, a dropdownlist, a checkbox, a button, and an update
I have a WPF listbox control that is declaratively bound to a textbox. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.