wiswalld
asked on
Insert a new row into a bound datagridview
Insert a new row into a bound datagridview
Database table - assignedvehicles
Tableadapter - assignedvehiclestableadapt er
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.
Database table - assignedvehicles
Tableadapter - assignedvehiclestableadapt
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ok,
You must do cad_050107dataset.Tables(0 ).Rows.Add to add a new row
To pull som info you can datagridview1.CurrentRow.C ells(0).Va lue.ToStri ng
You must do cad_050107dataset.Tables(0
To pull som info you can datagridview1.CurrentRow.C
ASKER
Me._CAD_050107DataSet.Tabl es(0).Rows .Add()
<column eventnumber does not allow nulls>
eventnumber is not null
<column eventnumber does not allow nulls>
eventnumber is not null
You have no values in the datagridview ?
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
How can I do this from datagridview1. It works from a button.
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
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
ASKER
Dim dr As DataRow = Me._CAD_050107DataSet.Tabl es(0).NewR ow
dr(1) = EventNumber.Text
dr(2) = Datagridview1.CurrentRow.C ells(1).Va lue.ToStri ng
Me._CAD_050107DataSet.Tabl es(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
dr(1) = EventNumber.Text
dr(2) = Datagridview1.CurrentRow.C
Me._CAD_050107DataSet.Tabl
I am not sure how to adapt for the names for datagridview2
Sorry for the "do it" not really politically correct. LOL
ASKER
Sorry I got it. Didn't mean to sound stupid.
Dim dr As DataRow = Me._CAD_050107DataSet.Tabl es("assign edvehicles ").NewRow
'Put values into row
dr(1) = EventNumber.Text
dr(2) = Datagridview1.CurrentRow.C ells(1).Va lue.ToStri ng
'and so on, making sure you put values in any ...
'... fields/columns that do not allow null
Me._CAD_050107DataSet.Tabl es("assign edvehicles ").Rows.Ad d(dr)
Dim dr As DataRow = Me._CAD_050107DataSet.Tabl
'Put values into row
dr(1) = EventNumber.Text
dr(2) = Datagridview1.CurrentRow.C
'and so on, making sure you put values in any ...
'... fields/columns that do not allow null
Me._CAD_050107DataSet.Tabl
ASKER