Click here to Skip to main content
15,885,772 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need a simple example of inserting data into grid view from a text box in vb on button click
Posted
Comments
Member 10919648 11-Aug-14 5:14am    
In vb.net

It is really not as simple as your questions appears.

A DataGridView consists of Rows and Columns, each of which can be addressed separately. It does not matter where the data comes from, what is important is to understand how to add data to the DataGridView either per Row or Cell.

To add a new row to a DataGridView you simply use the .Rows.Add syntax. However it is important to understand that when adding a row to a DataGridView, you have to separate the data according to the Columns you have have in the DataGridView.

For example: You have a DataGridView with 3 columns, each of them holding different data e.g.: First Name, Middle Name, Last Name. Now you wish to add the following information: John S Doe. Your syntax will look something like this:

VB
DataGridView.Rows.Add("John", "S", "Doe")


If the information comes from TextBoxes e.g.:
txtFirstName
txtMiddleName
txtLastName

Your code will look something like this:

VB
DataGridView.Rows.Add(txtFirstName.Text, txtMiddleName.Text, txtLastName.Text)


As you can see, it does not matter where the data comes from, it matters how you insert that into the DataGridView.

As for inserting data in specified locations (Cells) in the DataGridView, you can use the following code as a stepping stone to get you going:

VB
DataGridView.Rows(DataGridView.Rows.Count - 1).Cells(1).Style.BackColor = Color.Red


What the above code does is to change the BackGroundColor of a specific Cell in the DataGridView. This is merely a snippet from actual code and should be treated as such.

Hope this helps.

In future try to show us what you have tried because we would hate to do your homework for you as you will not learn anything if we keep doing your homework for you.
 
Share this answer
 
Refer this link

insert-data-in-grid-view-without-using-database.aspx[^]

It's in c# but i don't feel it will be much problem to do the same in vb.net
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900