2 Replies - 40025 Views - Last Post: 15 November 2009 - 09:10 AM Rate Topic: -----

#1 Essel  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 118
  • Joined: 08-May 09

Adding Data into datagridview

Post icon  Posted 15 November 2009 - 07:30 AM

I want to add data into different field using the datagridview.This is how i want it to work i have some combo boxes and textboxes on my form and any time i type some in them i want the data to be entered into an appropriate field/column in the datagrid view...........like this if the data in a txtbox goes to a particular column in the datagrid and the the value or data in another combo box goes to another column of the datagrid view.
I am using this code but it is not working for me it is just adding for the fisrt row in the datagrid and it is not moving to another column

dgexams.rows.add(me.cmbapplicantID.text)


Please i need your help

Is This A Good Question/Topic? 0
  • +

Replies To: Adding Data into datagridview

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Adding Data into datagridview

Posted 15 November 2009 - 07:43 AM

In order to put text into a specific column, a row has to exist. Therefore, if you have a 3 column datagridview their column indexes are 0, 1 and 2

To create a row with data in column 1 (the second visible column) you could use

DataGridView1.Rows.Add(nothing, "Charlie", Nothing)



This will add a new row with the 1st and 3rd visible column blank but the 2nd visible column will contain the word Charlie

Additionally, if you later wanted to go back to that row and insert a value in the 3rd column you could use

DataGridView1.Rows(0).Cells(2).Value = "May"



Of course, there are other means of locating the row you want to edit with Methods like CurrentRow but I don't want to create any confusion at this point.

You might also benefit from motcom's tutorial on manipulating an un-bound DataGridView

http://www.dreaminco...topic133407.htm

This post has been edited by CharlieMay: 15 November 2009 - 07:45 AM

Was This Post Helpful? 1
  • +
  • -

#3 Donnie1581  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 57
  • Joined: 05-November 09

Re: Adding Data into datagridview

Posted 15 November 2009 - 09:10 AM

After you fill and display your data grid, you can make changes inside the data grid. Add a new button to your form and put the following code in the button click event.

dim dataAdapter as New OleDB.OleDbDataAdapter(sqlStr, connstr)
Dim commandBuilder as New OleDB.OleDBCommandBuilder (dataAdapter) 
dim changes as integer = 0 
changes = dataAdapter.Update(dt)
dataAdapter.Dispose()
if changes >0 Then
MessageBox.Show ( changes & "changed rows were stored in the database")
else
MessageBox.Show ("No Changes were Made")



The dt in parenthesis is the variable of the data table you created.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1