Q: Dataview and a grid

  • Thread starter Thread starter G .Net
  • Start date Start date
G

G .Net

Hi

Can anybody help with the following?

I have a datagrid which has a dataview of a datatable in a dataset as a
view. I can add new rows to the grid, however I'm puzzled as to how to pass
these changes to the database i.e. if I simple use Update on the table, the
rows I've added to the grid aren't written to the database.

Can anybody help?

Thanks in advance

Geoff
 
Geoff,

Mostly is the point that there is only an endcurrentedit needed direct
before your update statement.


BindingContext("dv").EndCurrentEdit()

Something like that where the dv stends for your datasource

I hope this helps

Cor
 
Hi Cor

Thanks for your suggestion. I think I may have found a solution to my
problem by an alternative method. However, I hope you may be able to help
with a related matter.

The DataView I'm using as the datasource to the grid has a filter. The
condition for the filter is not one of the fields being displayed. So, for
example, if the grid displays two columns A and B, the value in column C
(which is not displayed) is the filter condition.

The problem I have is that I add data to the grid and obviously because the
value in C is not being inputted in the grid, the row immediately disappears
after inputting data. How can I write a value into C as soon as the user
starts adding data to the row in the grid so it doesn't disappear i.e. the
filter condition will be satisfied.

Thanks in advance

Geoff
 
Georg,

Better is not to extend questions with new questions, maybe is there
somebody who knows the answer direct. Because of what you ask, I use a
button to add on a screen.

I thought that there was a solution, so maybe it is better to make a new
message.

Cor
 
If AllowNew is true you can use the AddNew method of the DataView to create a new DataRowView. Note that a new row is not actually added to the underlying DataTable until the EndEdit method of the DataRowView is called. If the CancelEdit method of the DataRowView is called, the new row is discarded.

Dim custTable As DataTable = custDS.Tables("TBL1")
Dim custView As DataView = custTable.DefaultView

custView.AllowDelete = False

Dim newDRV As DataRowView = custView.AddNew()
newDRV("Field1") = "ABCDE"
newDRV("Field2") = "ABCDE Descr"
newDRV.EndEdit()
As an alternative download IdeaBlade’s DevForce Express and use that for ORM (I don’t work for them – but use it extensively)
 
Back
Top