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 / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

listbox doesn't refresh after adding an item

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dennis - 23 Oct 2004 13:39 GMT
listbox doesn't refresh after adding an item.

On a page I have 4 listboxes, the last three of which are child entries of
the previous.  Works fine.

Above each listbox I have a New button.  New opens up a NewConcepts form in
an AddNew state. I fill in the new concept, update the database and the form
closes.

NewConcepts was opened showdialog so focus returns to the listboxes.  I
would have expected the listbox to show the new concept, but it doesn't.  
Here is the code for the relevant New button:

 Private Sub btnNewC0_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNewC0.Click
       Dim frm As New frmNewConcept
       With frm
           '.iNew = Me.lstConcepts0.SelectedValue this is true for all the
others
           .iNew = 0
           .iNewAddMode = True
           .ShowDialog()
       End With
       'Dim int As Integer = frm.iAddNumber
       'MsgBox(int.ToString)
       If frm.iAddNumber > 0 Then
           Me.dsC.Clear()
           Me.daC.Fill(dsC, "Concepts")
           Me.lstConcepts0.Refresh()
       End If
       frm.Dispose()
   End Sub
   
If I check the database, the new concept is there.  If I close the form and
reopen it, the new concept is there.

Can somebody please be so kind as to show me how to persuade the listbox to
show the new item?

Thank you.

Dennis
Dennis - 24 Oct 2004 15:23 GMT
listbox doesn't refresh after adding an item.

On a page I have 4 listboxes, the last three of which are child entries of
the previous.  Works fine.

Above each listbox I have a New button.  New opens up a NewConcepts form in
an AddNew state. I fill in the new concept, update the database and the form
closes.

NewConcepts was opened showdialog so focus returns to the listboxes.  I
would have expected the listbox to show the new concept, but it doesn't.  
Here is the code for the relevant New button:

 Private Sub btnNewC0_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNewC0.Click
       Dim frm As New frmNewConcept
       With frm
           '.iNew = Me.lstConcepts0.SelectedValue this is true for all the
others
           .iNew = 0
           .iNewAddMode = True
           .ShowDialog()
       End With
       'Dim int As Integer = frm.iAddNumber
       'MsgBox(int.ToString)
       If frm.iAddNumber > 0 Then
           Me.dsC.Clear()
           Me.daC.Fill(dsC, "Concepts")
           Me.lstConcepts0.Refresh()
       End If
       frm.Dispose()
   End Sub
   
If I check the database, the new concept is there.  If I close the form and
reopen it, the new concept is there.

Can somebody please be so kind as to show me how to persuade the listbox to
show the new item?

Thank you.

Dennis

Addition

Actually, I've discovered the problem is much deeper than I thought. After
adding a new concept and closing the NewConcept form, the listboxes are not
functional any more.  No matter which item I select in the lstConcepts0
listbox, the other three listboxes remain the same.  When I changed
selections in the lstConcepts1 listbox, I got the following error:

system.data.rownotintableexception. this row has been removed from a table
and does not have an data.....
at .......lstConcepts!_SelectedValueChanged...line 1973

line 1873 is within the lstConcepts_SelectedValueChanged

  Private Sub lstConcepts1_SelectedValueChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles lstConcepts1.SelectedValueChanged
       Dim r As Dataset1.ConceptsRow = CType(Me.lstConcepts1.SelectedItem,
Dataset1.ConceptsRow)
       Try
           Me.lstConcepts2.DataSource =
dsC.Concepts.FindByID(r.ID).GetChildRows("ConceptsConcepts")
           iParentID2 = lstConcepts1.SelectedValue

this line Me.lstConcepts2.DataSource =
dsC.Concepts.FindByID(r.ID).GetChildRows("ConceptsConcepts")

However, when I close the form and reopen it, everything is ok again.

It seems it ought to be easy to refresh the listbox to include the added
concept.  I would really appreciate some help.

Dennis

> listbox doesn't refresh after adding an item.
>
[quoted text clipped - 38 lines]
>
> Dennis
"Jeffrey Tan[MSFT]" - 25 Oct 2004 08:40 GMT
Hi Dennis,

Based on my understanding, you use "New" button to open a form to input new
record, then update the typed dataset. After the form is closed, you update
the dataset's change to the database. But you find the listbox which is
bound to the dataset did not reflect out the change in the dataset.

Winform databinding is a 2 ways databinding, that is the change in the
underlying datasource(dataset) will immediately reflect to the UI(listbox).
I can not reproduce our your issue yet.

I think this issue should have nothing to do with the database, because the
UI only reflect the change of datasource. I suggest you create a sample
project(which gets rid of the database dependency) to help me to reproduce
your issue, then I can understand your issue much better, and help you to
figure out the problem.(You may attach the reproduce project as an
attachment in a reply) I will wait for your further feedback, thanks!
======================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dennis - 25 Oct 2004 13:01 GMT
Jeffrey,

Thank you very much.  I read your answer, and removed the following
statements from my button_click handler

           Me.dsC.Clear()
           Me.daC.Fill(dsC, "Concepts")
           Me.lstConcepts0.Refresh()
After that it worked fine.

Thanks again.

Dennis

> Hi Dennis,
>
[quoted text clipped - 23 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 26 Oct 2004 07:13 GMT
Hi Dennis,

I am glad your problem resolved!! If you need further help, please feel
free to post, I will work with you. Thanks!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dennis - 24 Oct 2004 15:27 GMT
Please excuse the reply above.  Its a repeat with the addition at the end.

Actually, I've discovered the problem is much deeper than I thought. After
adding a new concept and closing the NewConcept form, the listboxes are not
functional any more.  No matter which item I select in the lstConcepts0
listbox, the other three listboxes remain the same.  When I changed
selections in the lstConcepts1 listbox, I got the following error:

system.data.rownotintableexception. this row has been removed from a table
and does not have an data.....
at .......lstConcepts!_SelectedValueChanged...line 1973

line 1873 is within the lstConcepts_SelectedValueChanged

  Private Sub lstConcepts1_SelectedValueChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles lstConcepts1.SelectedValueChanged
       Dim r As Dataset1.ConceptsRow = CType(Me.lstConcepts1.SelectedItem,
Dataset1.ConceptsRow)
       Try
           Me.lstConcepts2.DataSource =
dsC.Concepts.FindByID(r.ID).GetChildRows("ConceptsConcepts")
           iParentID2 = lstConcepts1.SelectedValue

this line Me.lstConcepts2.DataSource =
dsC.Concepts.FindByID(r.ID).GetChildRows("ConceptsConcepts")

However, when I close the form and reopen it, everything is ok again.

It seems it ought to be easy to refresh the listbox to include the added
concept.  I would really appreciate some help.

Dennis

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.