2nd problem with that listbox doesn't refresh after adding an ite

G

Guest

2nd problem with that listbox doesn't refresh after adding an item.

When I originally submitted this problem and received a much appreciated
solution from Jeffry, I tried the new button only with lstConcepts0, which
worked fine. However, it doesn't work for any other of the three listboxes.
I even tried the following:

Private Sub btnNewC1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnNewC1.Click
Dim frm As New frmNewConcept
With frm
.iNew = Me.lstConcepts0.SelectedValue
.iNewAddMode = True
.ShowDialog()
End With
frm.Dispose()
Dim i As Integer = lstConcepts0.Items.Count
Dim iSelected As Integer
iSelected = lstConcepts0.SelectedIndex
Select Case iSelected
Case Is = i - 1
lstConcepts0.SelectedIndex = iSelected - 1
lstConcepts0.SelectedIndex = iSelected + 1
Case Else
lstConcepts0.SelectedIndex = iSelected + 1
lstConcepts0.SelectedIndex = iSelected - 1
End Select
End Sub

Not surprisingly, it didn't help at all.

Jeffrey suggested I send a sample app as an attachment. I normally use the
web news reader. I tried Outlook Express, but didn't see attachments someone
graciously sent me, nor did I see how to attach any files. Perhaps somebody
could tell me exactly how to add and download attachments. The help file
wasn't helpful.

Thanks,

Dennis

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


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

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
 
G

Guest

From your code, nothing should happen. Examine the code branch:
'Assume value here is 2
iSelected = lstConcepts0.SelectedIndex
Select Case iSelected
Case Is = i - 1
lstConcepts0.SelectedIndex = iSelected - 1
'value is now 1
lstConcepts0.SelectedIndex = iSelected + 1
'value is now 2
Case Else
lstConcepts0.SelectedIndex = iSelected + 1
'value is now 3
lstConcepts0.SelectedIndex = iSelected - 1
'value is now 2
End Select

With your code, you are going forward and back to the same number, or
backwards and forward to the same number.

Web or Winforms app?

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
G

Guest

Thank you Gregory.

Perhaps I didn't make myself understood clearly. The New button was for a
new entry into lstConcepts1. I thought since each listbox's contents are
children of the previous listbox's contents, that if I shuffled
lstConcepts0, the parent of lstConcepts1, then when I returned to the correct
parentID for lstConcepts1, the new entry would occur. But it didn't.

Do you have any suggestions to help me entry a new concept into lstconcepts1
and when the form closes the listbox is updated?

Thanks in advance, and sorry for the confusion.

Dennis
 
J

Jeffrey Tan[MSFT]

Hi Dennis,

I have followed up you in your original post, you may attach a sample
project to help us reproduce this issue. 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.
 
D

Dennis Turner

Jeffrey, I suddently contracted a wicked infection which has my head
spinning, my temperature heading towards the surface temperature of the Sun.
I'm taking 2 species of antibiotics.

So it might be a day or two before I have the application ready for you.

dennis
 
J

Jeffrey Tan[MSFT]

Hi Dennis,

No problem. I will wait for your further reply with attachment. Btw: take
care! Health is the most important thing!

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.
 
D

Dennis Turner

Jeffrey,
A funny error intruded on the way to the sample. I'm including the sample
as an attachment, but will first describe the error. Instructions. Build,
adjust for path differences. Then run. You will get the error with a
complete description and line number as the application opens. If you could
be so kind as to help me with this (it doesn't happen in my regular app and
I can't figure out why it happens here), we can get back to the main
problem.

Dennis




Jeffrey, I've been trying for two days to send a sample. The latest sample
was down to 50.9kb zipped but was rejected for being too large.

Here's what I'm going to do. I'm going to break it into 10kb rar files and
try that. If it won't accept rar files I'll convert each rar file into a
zip file. I'd guess you'll know how to untangle that.

Put the datahase into the bin folder.
 
D

Dennis

For some reason outlook express won't send my messages anymore. I've just
been on the phone with my isp. Let's see if this one gets there.

dennis
 
J

Jeffrey Tan[MSFT]

Hi Dennis,

Thanks very much for your feedback!

Yes, I have received your attachment and tried to run it. But there is
still some problem.

First, after moving the mdb file to the bin folder, I can succesfully show
out the "Concepts" form, but when I click any of the "New" button on the
form, I got "IndexOutOfRangeException" in frmNewConcept_Load event.

In details, I see that this exception is thrown by
"daNewConcept.SelectCommand.Parameters(0).Value = Me.iNew" statement, which
means SelectCommand's parameter collection is empty.

I think you should first get rid of other errors and exceptions, then I can
focus my effect on your exactly problem.

Also , I suggest you provided the more information such as reproduce
steps(such as first click which button, then click another listbox),
exptected result, and actual result for me, this will help me catch the
problem's keypoint better. Like below:
======== Steps to reproduce ========
1) repro steps
2) Actual results if any
3) Expected results if any

Anyway, I will wait for your further feedback.
==================================================
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.
 
D

Dennis

Thank you Jeffrey,

I tried hard to fix the index out of range exception, but was unable. I
checked the October MSDN library but couldn't find the information I needed.
Should I first put this problem separately in another thread, then come back
to this thread when I get the answer to that.

As far as the steps.
1. Without changing any selected item, click the New button over
lstConcepts1. When the NewConcepts form is displayed, type xxyyzz or any
similar letters into the concepts textbox. Click update. The form should
close and the new concept should appear in lstConcepts1, but doesn't.

Dennis
 
D

Dennis

Thank you Jeffrey,

I tried hard to fix the index out of range exception, but was unable. I
checked the October MSDN library but couldn't find the information I needed.
Should I first put this problem separately in another thread, then come back
to this thread when I get the answer to that.

As far as the steps.
1. Without changing any selected item, click the New button over
lstConcepts1. When the NewConcepts form is displayed, type xxyyzz or any
similar letters into the concepts textbox. Click update. The form should
close and the new concept should appear in lstConcepts1, but doesn't.

Dennis
 
J

Jeffrey Tan[MSFT]

Hi Dennis,

Thanks very much for your feedback!

Oh, I see, I think there is no need for you to post a new thread for this
issue, I will first help you out for this new index out of range exception,
after we figure this out, then we can focus on the original issue. But
currently I received several sample reproduce projects of other issues, so
I will spend a little more time on your issue, I will update your issue
ASAP. Thanks for your understanding!

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.
 
G

Guest

Jeffrey,

I found an error in the select command text in daNewConcept. I corrected it
with SELECT Active, Concept, ID, ParentID FROM Concepts WHERE (ParentID = ?)
and regenerated the parameter collection. However, now I get a new error.
The NewConcept form opens. But when I type something in the concept textbox
and click update I get the error message:


The field concepts.parentid cannot contain a null value....

However you can see from the messageboxes I put in that me.inew is not null.
I can't figure this one out either. It does not happen in the original.

Dennis
 
K

Kevin Yu [MSFT]

Hi Dennis,

From the error message, it seem that the ParentID field is not nillable. I
would like to see your code and check if the inew has been assigned to
table cell. Could you also send me a copy of project with SELECT Active,
Concept, ID, ParentID FROM Concepts WHERE (ParentID = ?) modified?

If you have concerns on ADO.NET issues such as DataAdapter filling and
updating, you can also start a new thread in
microsoft.public.dotnet.framework.adonet newsgroup. I will help you out in
that group.

Thanks!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi Dennis,

I have checked the project and found that the error message shows because
you didn't set any data binding on the NewConcept form. Since the data
binding wasn't set, the input data cannot be add to the DataSet. The
parentid field in Concept table in the database has been set to required,
so when updating, an exception will be thrown.

Please try to bind all controls to correct data source, so that the update
function works as expected.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Kevin,

Thank you. That oversight occured in my rush to cobble together
ConceptNewConcept for Jeffrey. The databinding was in place in
TopicFromStart.

This leaves the original problem. When NewConcept closes, the appropriate
listbox in the underlying form is not updated with the new concept. I've
tried a number of things that you don't see in ConceptNewConcept. For
example, I tried clearing the dataset and refilling it in the New button
after disposing frm. That just led to more errors. Jeffrey told me
databinding is two ways and it should show. That's why I cobbled together
ConceptNewConcept, but got caught at the error which you so kindly corrected.

Dennis
 
J

Jeffrey Tan[MSFT]

Hi Dennis,

Thanks very much for your feedback!!

So after you tried my colleague Kevin's suggestion of setting databinding
for the dataset in NewConcept form, are all the problems resolved? If you
still need help, please feel free to feedback with details problem
description, we 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.
 
G

Guest

I thought I'd put my reply here so we don't run off the right hand side of
the frame...

Thanks Jeffrey

Kevin's answer

Hi Dennis,

I have checked the project and found that the error message shows because
you didn't set any data binding on the NewConcept form. Since the data
binding wasn't set, the input data cannot be add to the DataSet. The
parentid field in Concept table in the database has been set to required,
so when updating, an exception will be thrown.

Please try to bind all controls to correct data source, so that the update
function works as expected.

Only referred to the error message I was getting regarding the parameter
value. Once that was fixed, the original error was still there. The
listboxes in Concepts were not updated when a new concept was added in the
NewConcept form. I've checked the database and sure enough the database is
updated. If I close ConceptNewConcept and run it again, the addition will
show. This is a curious and serious problem for me.

Thanks again, Jeffrey.

Dennis
 
G

Guest

Jeffrey,

Your post with the attachment and explanation showed up on the web reader,
but not on outlook express, so I couldn't download the attachment.

If possible, could you send the attachment to my no-spam address. It's a
real address and I will receive it there.

Thanks very much for all your work.

Dennis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top