PC Review


Reply
Thread Tools Rate Thread

datagrid doesn't reflect addnew to dataset

 
 
=?Utf-8?B?cG9seW5vbWlhbDVk?=
Guest
Posts: n/a
 
      11th Apr 2004
datagrid doesn't reflect addnew to dataset

I have a form which includes a currency manager (cm), a dataset with one table, and a set of controls that shows the table one row at a time. The buttons allow edit, delete, addnew, update the dataset, and submitchanges (update the dataadapter)

The form also includes a grid whose datasource is the dataset's one table. There is no relation between the two except two different views of the same table. The grid is readonly, parent rows are hidden. I had no problem using the mousedown event and hittest method of the grid, and the position properties of the grid and the currency manager to keep the rows in sync

I am having a big problem, however. If I edit a row or delete a row, and then update the dataset, these are reflected in the grid. However, if I add a row, it is not reflected. Even after I update the dataadapter the new row doesn't appear

Can someone help me on this

polynomial5d
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      11th Apr 2004
Hi Poly,

I think the best to get help from us is show some code where you add the row
to the datatable, because normaly it would be showed.

Cor


 
Reply With Quote
 
=?Utf-8?B?cG9seW5vbWlhbDVk?=
Guest
Posts: n/a
 
      11th Apr 2004
Cor

You're right, sorry. I'm putting in the code of all the relevant procedures so you and others can put the add into perspective

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Clic
cm.AddNew(
SetEditMode(True
End Su

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Clic
If cm.Count > 0 The
cm.RemoveAt(cm.Position
Els
MessageBox.Show("No Item to Delete!", "Delete Item", MessageBoxButtons.OK, MessageBoxIcon.Error
End I
End Su

Private Sub btnSubmitChanges_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmitChanges.Clic
If DsDT1.HasChanges The
DTypeOpened = Fals
Tr
Dim intModified As Intege
intModified = daDT.Update(DsDT1.DateType
Dim strOutput As Strin
strOutput = "Modified " & intModified & " item(s)
MessageBox.Show(strOutput, "Update succeeded!", MessageBoxButtons.OK, MessageBoxIcon.Information
DTypeOpened = Tru
Dim s = ControlChars.CrL
Catch ex As OleDbExceptio
If ex.Errors(0).SQLState = 3022 The
MsgBox(ex.Errors(0).Message & s & "Please try again"
DsDT1.Clear(
daDT.Fill(DsDT1, "DateType"
Exit Tr
Els
Dim errorMessages As Strin
errorMessages += "Message: " & ex.Errors(0).Message & ControlChars.CrLf
& "NativeError: " & ex.Errors(0).NativeError & ControlChars.CrLf
& "Source: " & ex.Errors(0).Source & ControlChars.CrLf
& "SQLState: " & ex.Errors(0).SQLState & ControlChars.CrLf
& "The form will be closed
MsgBox(errorMessages
Me.Close(
End I
Catch ex As DBConcurrencyExceptio
MsgBox(ex.Message & s & "The dataset will be refreshed." & s & "Then you can navigate to the row and update it again."
DsDT1.Clear(
daDT.Fill(DsDT1, "DateType"
Exit Tr
Catch ex As Exceptio
MsgBox(ex.GetType.ToString & s & ex.Message & s & ex.HelpLink & s & ex.StackTrace & s & ex.Source & s & "The form will be closed") '& s & ex.TargetSite
Me.Close(

End Tr
Els
MessageBox.Show("No changes to submit!", "SubmitChanges", MessageBoxButtons.OK, MessageBoxIcon.Information
End I

End Su

Private Sub SetEditMode(ByVal blnEdit As Boolean
'txtID.ReadOnly = Not blnEdi
txtDateType.ReadOnly = Not blnEdi
chkActive.Enabled = blnEdi

btnMoveFirst.Enabled = Not blnEdi
btnMovePrevious.Enabled = Not blnEdi
btnMoveNext.Enabled = Not blnEdi
btnMoveLast.Enabled = Not blnEdi

btnCancel.Enabled = blnEdi
btnUpdate.Enabled = blnEdi
btnEdit.Enabled = Not blnEdi
btnAdd.Enabled = Not blnEdi
btnDelete.Enabled = Not blnEdi
btnSubmitChanges.Enabled = Not blnEdi
End Su

Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Clic
If cm.Count > 0 The
SetEditMode(True
Els
MessageBox.Show("No Item to Edit!", "Edit Item", MessageBoxButtons.OK, MessageBoxIcon.Error
End I
End Su


Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Clic
cm.EndCurrentEdit(
SetEditMode(False
End Su

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Clic
cm.CancelCurrentEdit(
SetEditMode(False
End Sub

polynomial5d
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      11th Apr 2004
Hi Polynamial,

I have looked to that add routine, you do everything with the concurrency
manager (i asume the cm is the concurrencymanager. However what is binded
to that?

Cor


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      11th Apr 2004
And than before I ask a next question, what is the datasource of your
datagrid?

Cor


 
Reply With Quote
 
=?Utf-8?B?cG9seW5vbWlhbDVk?=
Guest
Posts: n/a
 
      12th Apr 2004
Cor,

I hope by the first question you mean this:

cm = CType(BindingContext(DsDT1, "DateType"), CurrencyManager)
AddHandler cm.ItemChanged, AddressOf cm_ItemChanged
AddHandler cm.PositionChanged, AddressOf cm_PositionChanged

And by the second question you mean this:

DsDT1.DateType

polynomial5d
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      12th Apr 2004
Hi Poly,

I never use it like this, however I tried it and got the same behaviour
using the dataset in the currencymanager, when I was using a dataview it
though it did work as wanted.

Can you try it. It is very easy to add.

dim dataview as new dataview(dsdt1.Tables("DateType")
cm = CType(BindingContext(dv), CurrencyManager)
> AddHandler cm.ItemChanged, AddressOf cm_ItemChanged
> AddHandler cm.PositionChanged, AddressOf cm_PositionChanged
>
> And by the second question you mean this:
>

And somewhere there has to be now
Datagrid1.datasource = dsdt1.tables("DataType") ' or something like that.
Datagrid1.datasource = dv

When you use the designer than you could drag a dataview to your form and
set the datasource in that as I did in code and than you can set the
dataview in the datagrid as the datasource.

Just to try, for me I thought this did work as wanted.

Cor


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      12th Apr 2004
Hi Poly,

There was a problem almost the same as yours in another newsgroup.
I told you I never use the bindingmanager to add a record.
However when I tested again with the bc.addnew I thought that I got
unpredictable results. When you keep having that also, can you than try what
it does when you change that addnew for this.

ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)

where ds is the dataset and 0 the table in the dataset (may also be the
table name between "")

Cor


 
Reply With Quote
 
=?Utf-8?B?cG9seW5vbWlhbDVk?=
Guest
Posts: n/a
 
      13th Apr 2004
datagrid doesn't reflect addnew to dataset

I have a form which includes a currency manager (cm), a dataset with one table, and a set of controls that shows the table one row at a time. The buttons allow edit, delete, addnew, update the dataset, and submitchanges (update the dataadapter)

The form also includes a grid whose datasource is the dataset's one table. There is no relation between the two except two different views of the same table. The grid is readonly, parent rows are hidden. I had no problem using the mousedown event and hittest method of the grid, and the position properties of the grid and the currency manager to keep the rows in sync

I am having a big problem, however. If I edit a row or delete a row, and then update the dataset, these are reflected in the grid. However, if I add a row, it is not reflected. Even after I update the dataadapter the new row doesn't appear

Can someone help me on this

polynomial5

Hi Poly

I think the best to get help from us is show some code where you add the ro
to the datatable, because normaly it would be showed

Co

Cor

You're right, sorry. I'm putting in the code of all the relevant procedures so you and others can put the add into perspective

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Clic
cm.AddNew(
SetEditMode(True
End Su

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Clic
If cm.Count > 0 The
cm.RemoveAt(cm.Position
Els
MessageBox.Show("No Item to Delete!", "Delete Item", MessageBoxButtons.OK, MessageBoxIcon.Error
End I
End Su

Private Sub btnSubmitChanges_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmitChanges.Clic
If DsDT1.HasChanges The
DTypeOpened = Fals
Tr
Dim intModified As Intege
intModified = daDT.Update(DsDT1.DateType
Dim strOutput As Strin
strOutput = "Modified " & intModified & " item(s)
MessageBox.Show(strOutput, "Update succeeded!", MessageBoxButtons.OK, MessageBoxIcon.Information
DTypeOpened = Tru
Dim s = ControlChars.CrL
Catch ex As OleDbExceptio
If ex.Errors(0).SQLState = 3022 The
MsgBox(ex.Errors(0).Message & s & "Please try again"
DsDT1.Clear(
daDT.Fill(DsDT1, "DateType"
Exit Tr
Els
Dim errorMessages As Strin
errorMessages += "Message: " & ex.Errors(0).Message & ControlChars.CrLf
& "NativeError: " & ex.Errors(0).NativeError & ControlChars.CrLf
& "Source: " & ex.Errors(0).Source & ControlChars.CrLf
& "SQLState: " & ex.Errors(0).SQLState & ControlChars.CrLf
& "The form will be closed
MsgBox(errorMessages
Me.Close(
End I
Catch ex As DBConcurrencyExceptio
MsgBox(ex.Message & s & "The dataset will be refreshed." & s & "Then you can navigate to the row and update it again."
DsDT1.Clear(
daDT.Fill(DsDT1, "DateType"
Exit Tr
Catch ex As Exceptio
MsgBox(ex.GetType.ToString & s & ex.Message & s & ex.HelpLink & s & ex.StackTrace & s & ex.Source & s & "The form will be closed") '& s & ex.TargetSite
Me.Close(

End Tr
Els
MessageBox.Show("No changes to submit!", "SubmitChanges", MessageBoxButtons.OK, MessageBoxIcon.Information
End I

End Su

Private Sub SetEditMode(ByVal blnEdit As Boolean
'txtID.ReadOnly = Not blnEdi
txtDateType.ReadOnly = Not blnEdi
chkActive.Enabled = blnEdi

btnMoveFirst.Enabled = Not blnEdit
btnMovePrevious.Enabled = Not blnEdit
btnMoveNext.Enabled = Not blnEdit
btnMoveLast.Enabled = Not blnEdit

btnCancel.Enabled = blnEdit
btnUpdate.Enabled = blnEdit
btnEdit.Enabled = Not blnEdit
btnAdd.Enabled = Not blnEdit
btnDelete.Enabled = Not blnEdit
btnSubmitChanges.Enabled = Not blnEdit
End Sub

Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
If cm.Count > 0 Then
SetEditMode(True)
Else
MessageBox.Show("No Item to Edit!", "Edit Item", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub



Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
cm.EndCurrentEdit()
SetEditMode(False)
End Sub

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
cm.CancelCurrentEdit()
SetEditMode(False)
End Sub

Hi Polynamial,

I have looked to that add routine, you do everything with the concurrency
manager (i asume the cm is the concurrencymanager. However what is binded
to that?

Cor

And than before I ask a next question, what is the datasource of your
datagrid?

Cor
And than before I ask a next question, what is the datasource of your
datagrid?

Cor

Cor,

I hope by the first question you mean this:

cm = CType(BindingContext(DsDT1, "DateType"), CurrencyManager)
AddHandler cm.ItemChanged, AddressOf cm_ItemChanged
AddHandler cm.PositionChanged, AddressOf cm_PositionChanged

And by the second question you mean this:

DsDT1.DateType

polynomial5d

Hi Poly,

I never use it like this, however I tried it and got the same behaviour
using the dataset in the currencymanager, when I was using a dataview it
though it did work as wanted.

Can you try it. It is very easy to add.

dim dataview as new dataview(dsdt1.Tables("DateType")
cm = CType(BindingContext(dv), CurrencyManager)
> AddHandler cm.ItemChanged, AddressOf cm_ItemChanged
> AddHandler cm.PositionChanged, AddressOf cm_PositionChanged
>> And by the second question you mean this:

>

And somewhere there has to be now
Datagrid1.datasource = dsdt1.tables("DataType") ' or something like that.
Datagrid1.datasource = dv

When you use the designer than you could drag a dataview to your form and
set the datasource in that as I did in code and than you can set the
dataview in the datagrid as the datasource.

Just to try, for me I thought this did work as wanted.

Cor

Hi Poly,

There was a problem almost the same as yours in another newsgroup.
I told you I never use the bindingmanager to add a record.
However when I tested again with the bc.addnew I thought that I got
unpredictable results. When you keep having that also, can you than try what
it does when you change that addnew for this.

ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)

where ds is the dataset and 0 the table in the dataset (may also be the
table name between "")

Cor

Cor,

The first two didn't work at all for me. Here's the code:

When I used dgrd.datasource = dsdt1.tables... the grid didn't fill at all.
When I used dgrd.DataSource = dv the grid filled.

However, in both cases when the cm wouldn't cycle. As I moved rows only the first row showed; furthermore when I clicked add the datetype textbox wasn't blank. It still showed the first row, and the datagrid(in the second case) produced a null in the datetype column, inevitably producing an exception unless I clicked cancel.

In the property boxes for the three bound controls, there was of course no option to select dataview.

I'm afraid to use your third option, because the solution would no longer be portable.

polynomial5d



cnDT.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDBatabase Locking Mode=1;Jet OLEDBatabase Password=;Data Source=""" + System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\HasbaraSample.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDBon't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False"
'cm = CType(BindingContext(DsDT1, "DateType"), CurrencyManager)
Dim dv As New DataView(DsDT1.Tables("DateType"))
cm = CType(BindingContext(dv), CurrencyManager)
dgrd.DataSource = DsDT1.Tables("DataType") ' or something like that.
'dgrd.DataSource = dv

 
Reply With Quote
 
=?Utf-8?B?cG9seW5vbWlhbDVk?=
Guest
Posts: n/a
 
      13th Apr 2004
Cor, when I tried to use the view, the wizard couldn't generate the update or delete commands becaus

Could not determine which columns uniquely identify the rows for "qryDateTypeAsc"

polynomial5d
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dataset displays in datagrid at runtime but designer doesn't see any datasources jollygreenguy@gmail.com Microsoft ADO .NET 0 12th Apr 2007 06:48 AM
Why won't Dataset reflect changes? =?Utf-8?B?Q290eQ==?= Microsoft ADO .NET 0 30th Mar 2006 07:00 PM
Database doesn't update from datagrid using dataset Assimalyst Microsoft ADO .NET 1 30th Sep 2005 03:09 PM
Datagrid doesn't reflect changes in datasource =?Utf-8?B?UmVuw6kgVGl0dWxhZXI=?= Microsoft Dot NET Framework Forms 2 26th Nov 2004 03:39 PM
datagrid doesn't reflect changes in data (unless datatable) Peter Bladh Microsoft Dot NET Compact Framework 4 15th Jan 2004 08:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:01 AM.