Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Insert a new row into a bound datagridview

Posted on 2007-07-21
11
Medium Priority
?
830 Views
Last Modified: 2008-01-09
Insert a new row into a bound datagridview

Database table - assignedvehicles
Tableadapter - assignedvehiclestableadapter
Dataset - _cad_050107dataset
Datagridview - Datagridview2

I want to insert a value from a textbox into cell 0 on the datagridview and insert cell 0 value from datagridview1 current row.
0
Comment
Question by:wiswalld
  • 6
  • 3
  • 2
11 Comments
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 800 total points
ID: 19538790
>> insert a value from a textbox into cell 0 on the datagridview

Datagridview2(0,0).Value = Textbox1.Text
0
 
LVL 13

Author Comment

by:wiswalld
ID: 19539036
When I do this I want to add a new row to the datagridview (datagridview2). I also want to pull some info from a selected row in datagridview1
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 19539118
Ok,

You must do cad_050107dataset.Tables(0).Rows.Add to add a new row

To pull som info you can datagridview1.CurrentRow.Cells(0).Value.ToString
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 13

Author Comment

by:wiswalld
ID: 19539189
Me._CAD_050107DataSet.Tables(0).Rows.Add()

<column eventnumber does not allow nulls>

eventnumber is not null
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 19539219
You have no values in the datagridview ?
0
 
LVL 13

Author Comment

by:wiswalld
ID: 19539269
Yes/Sometimes. Sometimes the datagridview will have no values. My datagridview shows assigned vehicles associated with the eventnumber from the form. So if the form eventnumber is 3 then all assigned vehicles for eventnumber 3 will or there will be none and I will add them using this method.
0
 
LVL 34

Accepted Solution

by:
Sancler earned 1200 total points
ID: 19539281
  Dim dr As DataRow = Me._CAD_050107DataSet.Tables(0).NewRow
   'Put values into row
   dr(0) = Textbox1.Text
   'and so on, making sure you put values in any ...
   '... fields/columns that do not allow null
   Me._CAD_050107DataSet.Tables(0).Rows.Add(dr)

Roger
0
 
LVL 13

Author Comment

by:wiswalld
ID: 19539377
How can I do this from datagridview1. It works from a button.
0
 
LVL 34

Expert Comment

by:Sancler
ID: 19539429
A bound datagridview is a display (and editing) mechanism for the data in the datatable to which it is bound.  If you add a record to that datatable then - provided it passes through any filter that you may have put between the datatable and the datagridview - it will, as soon as the

    myDataTable.Rows.Add(myRow)

is hit - appear in the datagridview.  So you can "do it" from anywhere.  If you put that code - adapted for your names, values, etc - into the Click event for the button you are referring to, it should work.

Roger
0
 
LVL 13

Author Comment

by:wiswalld
ID: 19539476
Dim dr As DataRow = Me._CAD_050107DataSet.Tables(0).NewRow
dr(1) = EventNumber.Text
dr(2) = Datagridview1.CurrentRow.Cells(1).Value.ToString
Me._CAD_050107DataSet.Tables(0).Rows.Add(dr)

I am not sure how to adapt for the names for datagridview2

Sorry for the "do it" not really politically correct. LOL
0
 
LVL 13

Author Comment

by:wiswalld
ID: 19539509
Sorry I got it. Didn't mean to sound stupid.

Dim dr As DataRow = Me._CAD_050107DataSet.Tables("assignedvehicles").NewRow
        'Put values into row
        dr(1) = EventNumber.Text
        dr(2) = Datagridview1.CurrentRow.Cells(1).Value.ToString
        'and so on, making sure you put values in any ...
        '... fields/columns that do not allow null
        Me._CAD_050107DataSet.Tables("assignedvehicles").Rows.Add(dr)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question