Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2007

Tip: Looking for answers? Try searching our database.

DataGridView Not Updating

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Octavius Khan - 15 Oct 2007 02:35 GMT
I have a DataGridView control on a Windows form and I am updating a dataset.
Everything works fine, and data is updating properly in the underlying
database.  However, changes to the dataset that I make in code does not
appear in the DataGridView.  For example, if I edit a cell of the
DataGridView, all works well with the following code:

Private Sub dg_Cases_CellEndEdit(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles dg_Cases.CellEndEdit
   If Me.CasesDataSet.HasChanges Then
   Me.CasesTableAdapter.Update(CasesDataSet.Cases)
   Me.CasesTableAdapter.Fill(CasesDataSet.Tables("Cases"))
End If
End Sub

However, when I use the code below to delete a row, two rows are actually
deleted.  Also, if I add a row in code, the new row does not appear in the
DataGridView control, although it is certainly added to the underlying
database, and it appears in the DataGridView if I reload my application:

Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs)
   CasesBindingSource.RemoveCurrent()
   CasesTableAdapter.Update(CasesDataSet.Cases)
   CasesTableAdapter.Fill(CasesDataSet.Cases)
End Sub

Is there something I need to do in order for changes to appear in the
DataGridView?  Calling the Refresh method does not cause the changes to
appear.

Thanks in advance for your assistance.
Cor Ligthert[MVP] - 15 Oct 2007 04:51 GMT
Octavius,

> Private Sub dg_Cases_CellEndEdit(ByVal sender As System.Object, ByVal e As
> System.Windows.Forms.DataGridViewCellEventArgs) Handles
> dg_Cases.CellEndEdit
>    If Me.CasesDataSet.HasChanges Then
>    Me.CasesTableAdapter.Update(CasesDataSet.Cases)

Above you update the DataBase nothing in the DataSet

>    Me.CasesTableAdapter.Fill(CasesDataSet.Tables("Cases"))

Above you add to the table everything that is in your select string

> Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As
> System.Object, ByVal e As System.EventArgs)
>    CasesBindingSource.RemoveCurrent()
>    CasesTableAdapter.Update(CasesDataSet.Cases)

Above you update the DataTable nothing in the DataSet

>    CasesTableAdapter.Fill(CasesDataSet.Cases)

Above you add to the table everything that is in your select string

> End Sub

You can clear the DataTable before the Select as you want to see changes
done by others too. However why are you using in your Select strongly typed
code and in your update raw Dataset code?

Cor
Octavius Khan - 15 Oct 2007 06:08 GMT
Sorry, but I don't understand what you are trying to tell me here.

> Octavius,
>
[quoted text clipped - 28 lines]
>
> Cor
Cor Ligthert[MVP] - 15 Oct 2007 06:17 GMT
Octavius,

Be aware that twice a fill, is filling two times a dataset.

If you want your code like this, then use the dataset.clear before the
second select.

However that can take time and should be avoided as there is no need for it.

Your deletes and adds should be already in your dataset, so why it is not
showed in your DataGridView would be probably another problem, that is not
direct related to the updating.

Cor
Octavius Khan - 15 Oct 2007 11:47 GMT
Okay. Now I understand.

Thanks.

> Octavius,
>
[quoted text clipped - 11 lines]
>
> Cor

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.