Technology Programming

How to Update a Row in Grid View

    • 1). Start Microsoft Visual Basic Express. Click "New Project..." on the left pane of your screen, then select "Windows Forms Application." Click "OK."

    • 2). Double-click "Button" on the "Toolbox" pane to add a new button control. Double-click "Button" again to add a second button to your Form. Double-click "DataGridView" to add a new grid control.

    • 3). Double-click "Button1" to open the "Form1.vb" module. Copy and paste the following code inside the "Button1_Click" subroutine to define data that will be added to the Data Grid View control:

      Dim row0 As String() = {"Ana", "Lopez", "Teacher"}

      Dim row1 As String() = {"Sylvia", "Gonzalez", "Business Admin"}

      Dim row2 As String() = {"Jaime", "Melendrez", "RF Engineer"}

      Dim row3 As String() = {"Mary", "Smith", "Manager"}

      With Me.DataGridView1.Rows

      .Add(row0)

      .Add(row1)

      .Add(row2)

      .Add(row3)

      End With

    • 4). Type the following to create the "DataGridViewSetup" subroutine that will add formatting and field headers to the Data Grid View control:

      Private Sub DataGridViewSetup()

      Me.Controls.Add(DataGridView1)

      DataGridView1.ColumnCount = 3

      With DataGridView1

      .RowHeadersVisible = False

      .Columns(0).Name = "First Name"

      .Columns(1).Name = "Last Name"

      .Columns(2).Name = "Position"

      .SelectionMode = DataGridViewSelectionMode.FullRowSelect

      .MultiSelect = False

      .Dock = DockStyle.Fill

      End With

      End Sub

    • 5). Click "Form1.vb [Design]" to view the Form in design mode and double-click the Form. Copy and paste the following code inside the "Form1_Load" subroutine to call the "DataGridViewSetup" subroutine:

      DataGridViewSetup()

    • 6). Click "Form1.vb [Design]" to view the Form in design mode. Double-click "Button2" to open the "Button2_Click" subroutine.

    • 7). Copy and paste the following code inside the "Button2_Click" to update the last row of the Data Grid View with new information and format the back and fore color of the row updated:

      With Me.DataGridView1.Rows

      .Item(3).Cells(0).Value = "John"

      .Item(3).Cells(0).Style.BackColor = Color.Red

      .Item(3).Cells(0).Style.ForeColor = Color.White

      .Item(3).Cells(1).Value = "Barker"

      .Item(3).Cells(1).Style.BackColor = Color.Red

      .Item(3).Cells(1).Style.ForeColor = Color.White

      .Item(3).Cells(2).Value = "Supervisor"

      .Item(3).Cells(2).Style.BackColor = Color.Red

      .Item(3).Cells(2).Style.ForeColor = Color.White

      End With

      Press "F5" to run your program, then click "Button1" to load the data and "Button2" to update the last row.

SHARE
RELATED POSTS on "Technology"
WordPress - How to Set up a New Theme to WordPress 3.
WordPress - How to Set up a New Theme to WordPress 3.
Solution of Creative Web Design
Solution of Creative Web Design
The three disciplines of User Experience
The three disciplines of User Experience
Web Design Sheffield Options For Professional Enterprises
Web Design Sheffield Options For Professional Enterprises
Do you have what it takes?
Do you have what it takes?
Segway Cost
Segway Cost
Microsoft Access 2010: What's Coming with Office 2010?
Microsoft Access 2010: What's Coming with Office 2010?
Companies of Web Development in Ireland Provide Designs that Work
Companies of Web Development in Ireland Provide Designs that Work
Penguin Update to Put Red-Flags on Negative SEO
Penguin Update to Put Red-Flags on Negative SEO
Innovative web 2 design templates can make your business famous quickly
Innovative web 2 design templates can make your business famous quickly
Building A Search Engine Friendly Website
Building A Search Engine Friendly Website
Exceptional Advice To Build Up Your Internet Marketing
Exceptional Advice To Build Up Your Internet Marketing
The Benefits of Selecting The Right Hosting Company
The Benefits of Selecting The Right Hosting Company
Is There a Methodology for Making Successful Logos
Is There a Methodology for Making Successful Logos
Benefits of Ruby On Rails Development
Benefits of Ruby On Rails Development
The Power of Colour and Shapes in Your Infant's Life.
The Power of Colour and Shapes in Your Infant's Life.
Advantages of Hiring PSD To HTML Service Providers
Advantages of Hiring PSD To HTML Service Providers
How to Make Responsive Web Design Attractive?
How to Make Responsive Web Design Attractive?
Converting PSD to Responsive HTML
Converting PSD to Responsive HTML
Just a few realy really hints and tips when it comes to website design but look for.
Just a few realy really hints and tips when it comes to website design but look for.

Leave Your Reply

*