How to Add a Text Box to DataGridView

Written by alexander gokhfeld
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Add a Text Box to DataGridView
DataGridView control lets programmers add text fields on Windows forms. (Jupiterimages/ Images)

The DataGridView control is a component of Microsoft .NET Framework Windows Forms. It enables users to enter and edit values in the form columns. You must define DataGridView Column and Cell classes if you want to add new column data types, such as a text box class. The text box class overrides the properties of the DataGridView control by using the Clone method. You need to copy GridView base in order to add text box cells to DataGridview.

Skill level:
Moderately Easy

Other People Are Reading


  1. 1

    Click the "Start" button in Windows, and select "Microsoft Office," "Microsoft Visual Studio."

  2. 2

    Click "Open" and select your C program in which you want to to add text box cells in DataGridView form.

  3. 3

    Add the following code after the "System.Windows.Forms" line in your program:

    Public Overrides Property CellTemplate() As DataGridViewCell

            Return TestBase.CellTemplate
        End Get
        Set(ByVal value As DataGridViewCell)
            If (value IsNot Empty) AndAlso _
                Not value.GetType().IsAssignableFrom(GetType(TextCell)) _
                Throw New InvalidCastException("Expected a TextCell")
            End If
            TestBase.CellTemplate = value
        End Set
    End Property
  4. 4

    Click the "File," "Save" to add text box cells in the DataGridView form of your C program.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.