listbox doesn't refresh after adding an item

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 
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
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
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,

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
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top