473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Listbox not refreshing

P K
Hi,

I have two listboxes on my form.
One has a list of available values while the other is a list of selected
values.
So I select a value from list 1 and add it to list 2 when "add" button is
clicked.
I can also select a value from list 2 and remove it on clicking "Remove"
button, which would again add it to list 1.

Now the lists are both bound to custom list objects. when I add or remove, I
manipulate the list and then rebind it to the list boxes.

The elements seem to get added but when I add element 1, a space is seen in
list 2. When I add element 2, element 1 is visible while element 2 is not
visisble. Same with remove.
So in essence, everytime I add or remove an object for the first time, I
cannot see the item in the list, though a blank row is seens. After every
subsequent add or remove the previous element becomes visible.

Any solutions please? Why can't the add and remove of items be seen
instantly ?

Thanks

Feb 6 '06 #1
4 1372
If the dropdownlists were being databound before the custom lists were
updated then one would get the situation that you described. Can you post
the code that clarifies the sequence of events that affect these
dropdownlists.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"P K" wrote:
Hi,

I have two listboxes on my form.
One has a list of available values while the other is a list of selected
values.
So I select a value from list 1 and add it to list 2 when "add" button is
clicked.
I can also select a value from list 2 and remove it on clicking "Remove"
button, which would again add it to list 1.

Now the lists are both bound to custom list objects. when I add or remove, I
manipulate the list and then rebind it to the list boxes.

The elements seem to get added but when I add element 1, a space is seen in
list 2. When I add element 2, element 1 is visible while element 2 is not
visisble. Same with remove.
So in essence, everytime I add or remove an object for the first time, I
cannot see the item in the list, though a blank row is seens. After every
subsequent add or remove the previous element becomes visible.

Any solutions please? Why can't the add and remove of items be seen
instantly ?

Thanks

Feb 6 '06 #2
P K
here is the seq of events -
1.
On form load
' bind the available list
Me.lstSalAvailable.DataSource = moSamplePopulationTypeList
Me.lstSalAvailable.DisplayMember = "Description"
Me.lstSalAvailable.ValueMember = "SPTypeID"

' bind the assigned list
Me.lstSalAssigned.DataSource = moProjectSampleTypeList
Me.lstSalAssigned.DisplayMember = "Description"
Me.lstSalAssigned.ValueMember = "SPTypeID"
2. On click of add button

Private Sub btnSalAssign_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSalAssign.Click
Dim oSelectedItem As Object
Dim x As Integer

If Me.lstSalAvailable.SelectedIndices.Count = 0 Then Exit Sub
Try
Me.Cursor = Cursors.WaitCursor
' enable the save button
btnSalSave.Enabled = True

For Each oSelectedItem In Me.lstSalAvailable.SelectedIndices
x = oSelectedItem.ToString()
AssignSamplePopulation(x)
Next
Catch ex As Exception
MsgBox(ex.Message & " " & ex.StackTrace)

Finally
' Enable save button
If Me.moSamplePopulationTypeList.IsDirty Then
Me.btnSalSave.Enabled = True
Else
Me.btnSalSave.Enabled = False
End If

Me.Cursor = Cursors.Default
End Try
End Sub

3.

Private Sub AssignSamplePopulation(ByVal index As Integer)
Dim oSamplePopulationType As CSamplePopulationType
Dim oProjectSampleType As CProjectSampleType

oSamplePopulationType = moSamplePopulationTypeList(index)

' add to assigned list
oProjectSampleType = Me.moProjectSampleTypeList.AddProjectSampleType

' Value indivudual properties
oProjectSampleType.ProjectID = moProject.ProjectID
oProjectSampleType.SPTypeID = oSamplePopulationType.SPTypeID
oProjectSampleType.GenericSalutationTemplate =
oSamplePopulationType.GenericSalutationDefault
oProjectSampleType.Description = oSamplePopulationType.Description
oProjectSampleType.CreatedBy =
CType(Thread.CurrentPrincipal.Identity,
SCS_Business_Layer.Security.CBusinessIdentity).Use rID
oProjectSampleType.LastModifiedBy =
CType(Thread.CurrentPrincipal.Identity,
SCS_Business_Layer.Security.CBusinessIdentity).Use rID

' remove from available list
moSamplePopulationTypeList.Remove(oSamplePopulatio nType)

'********** I tried this rebind below ......******************
' bind the available list
Me.lstSalAvailable.DataSource = moSamplePopulationTypeList
Me.lstSalAvailable.DisplayMember = "Description"
Me.lstSalAvailable.ValueMember = "SPTypeID"

' bind the assigned list
Me.lstSalAssigned.DataSource = moProjectSampleTypeList
Me.lstSalAssigned.DisplayMember = "Description"
Me.lstSalAssigned.ValueMember = "SPTypeID"

'************************************************* ***
Me.lstSalAssigned.Refresh()
Me.lstSalAvailable.Refresh()
End Sub

Similarly the unassign happens ....

Do let me know if you need more details

so.
say list 1 has following values 1, 2, 3, 4,5
list 2 has 7, 8
When I click value 2 and add it to list2, it sure does get added but a blank
line appears in list2. The value is invisible.Next, if I add value 3 to list2
then at this point value 2 which was added earlier becomes visible in list2
while the current value added which is 3 shows up as a invisible column.
"Phillip Williams" wrote:
If the dropdownlists were being databound before the custom lists were
updated then one would get the situation that you described. Can you post
the code that clarifies the sequence of events that affect these
dropdownlists.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"P K" wrote:
Hi,

I have two listboxes on my form.
One has a list of available values while the other is a list of selected
values.
So I select a value from list 1 and add it to list 2 when "add" button is
clicked.
I can also select a value from list 2 and remove it on clicking "Remove"
button, which would again add it to list 1.

Now the lists are both bound to custom list objects. when I add or remove, I
manipulate the list and then rebind it to the list boxes.

The elements seem to get added but when I add element 1, a space is seen in
list 2. When I add element 2, element 1 is visible while element 2 is not
visisble. Same with remove.
So in essence, everytime I add or remove an object for the first time, I
cannot see the item in the list, though a blank row is seens. After every
subsequent add or remove the previous element becomes visible.

Any solutions please? Why can't the add and remove of items be seen
instantly ?

Thanks

Feb 6 '06 #3
P K
Also I tried this thing and looked like it worked.
Just after all manipulations I unbound the lists and rebound them again to
thier objects. I looked like it worked.
I wouldn't mind a better solution though.

Thanks
PK

"P K" wrote:
here is the seq of events -
1.
On form load
' bind the available list
Me.lstSalAvailable.DataSource = moSamplePopulationTypeList
Me.lstSalAvailable.DisplayMember = "Description"
Me.lstSalAvailable.ValueMember = "SPTypeID"

' bind the assigned list
Me.lstSalAssigned.DataSource = moProjectSampleTypeList
Me.lstSalAssigned.DisplayMember = "Description"
Me.lstSalAssigned.ValueMember = "SPTypeID"
2. On click of add button

Private Sub btnSalAssign_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSalAssign.Click
Dim oSelectedItem As Object
Dim x As Integer

If Me.lstSalAvailable.SelectedIndices.Count = 0 Then Exit Sub
Try
Me.Cursor = Cursors.WaitCursor
' enable the save button
btnSalSave.Enabled = True

For Each oSelectedItem In Me.lstSalAvailable.SelectedIndices
x = oSelectedItem.ToString()
AssignSamplePopulation(x)
Next
Catch ex As Exception
MsgBox(ex.Message & " " & ex.StackTrace)

Finally
' Enable save button
If Me.moSamplePopulationTypeList.IsDirty Then
Me.btnSalSave.Enabled = True
Else
Me.btnSalSave.Enabled = False
End If

Me.Cursor = Cursors.Default
End Try
End Sub

3.

Private Sub AssignSamplePopulation(ByVal index As Integer)
Dim oSamplePopulationType As CSamplePopulationType
Dim oProjectSampleType As CProjectSampleType

oSamplePopulationType = moSamplePopulationTypeList(index)

' add to assigned list
oProjectSampleType = Me.moProjectSampleTypeList.AddProjectSampleType

' Value indivudual properties
oProjectSampleType.ProjectID = moProject.ProjectID
oProjectSampleType.SPTypeID = oSamplePopulationType.SPTypeID
oProjectSampleType.GenericSalutationTemplate =
oSamplePopulationType.GenericSalutationDefault
oProjectSampleType.Description = oSamplePopulationType.Description
oProjectSampleType.CreatedBy =
CType(Thread.CurrentPrincipal.Identity,
SCS_Business_Layer.Security.CBusinessIdentity).Use rID
oProjectSampleType.LastModifiedBy =
CType(Thread.CurrentPrincipal.Identity,
SCS_Business_Layer.Security.CBusinessIdentity).Use rID

' remove from available list
moSamplePopulationTypeList.Remove(oSamplePopulatio nType)

'********** I tried this rebind below ......******************
' bind the available list
Me.lstSalAvailable.DataSource = moSamplePopulationTypeList
Me.lstSalAvailable.DisplayMember = "Description"
Me.lstSalAvailable.ValueMember = "SPTypeID"

' bind the assigned list
Me.lstSalAssigned.DataSource = moProjectSampleTypeList
Me.lstSalAssigned.DisplayMember = "Description"
Me.lstSalAssigned.ValueMember = "SPTypeID"

'************************************************* ***
Me.lstSalAssigned.Refresh()
Me.lstSalAvailable.Refresh()
End Sub

Similarly the unassign happens ....

Do let me know if you need more details

so.
say list 1 has following values 1, 2, 3, 4,5
list 2 has 7, 8
When I click value 2 and add it to list2, it sure does get added but a blank
line appears in list2. The value is invisible.Next, if I add value 3 to list2
then at this point value 2 which was added earlier becomes visible in list2
while the current value added which is 3 shows up as a invisible column.
"Phillip Williams" wrote:
If the dropdownlists were being databound before the custom lists were
updated then one would get the situation that you described. Can you post
the code that clarifies the sequence of events that affect these
dropdownlists.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"P K" wrote:
Hi,

I have two listboxes on my form.
One has a list of available values while the other is a list of selected
values.
So I select a value from list 1 and add it to list 2 when "add" button is
clicked.
I can also select a value from list 2 and remove it on clicking "Remove"
button, which would again add it to list 1.

Now the lists are both bound to custom list objects. when I add or remove, I
manipulate the list and then rebind it to the list boxes.

The elements seem to get added but when I add element 1, a space is seen in
list 2. When I add element 2, element 1 is visible while element 2 is not
visisble. Same with remove.
So in essence, everytime I add or remove an object for the first time, I
cannot see the item in the list, though a blank row is seens. After every
subsequent add or remove the previous element becomes visible.

Any solutions please? Why can't the add and remove of items be seen
instantly ?

Thanks

Feb 6 '06 #4
I think you did it right. Set the DataSource to nothing then set it back
again at the end of the btnSalAssign_Click method.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"P K" wrote:
Also I tried this thing and looked like it worked.
Just after all manipulations I unbound the lists and rebound them again to
thier objects. I looked like it worked.
I wouldn't mind a better solution though.

Thanks
PK

"P K" wrote:
here is the seq of events -
1.
On form load
' bind the available list
Me.lstSalAvailable.DataSource = moSamplePopulationTypeList
Me.lstSalAvailable.DisplayMember = "Description"
Me.lstSalAvailable.ValueMember = "SPTypeID"

' bind the assigned list
Me.lstSalAssigned.DataSource = moProjectSampleTypeList
Me.lstSalAssigned.DisplayMember = "Description"
Me.lstSalAssigned.ValueMember = "SPTypeID"
2. On click of add button

Private Sub btnSalAssign_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSalAssign.Click
Dim oSelectedItem As Object
Dim x As Integer

If Me.lstSalAvailable.SelectedIndices.Count = 0 Then Exit Sub
Try
Me.Cursor = Cursors.WaitCursor
' enable the save button
btnSalSave.Enabled = True

For Each oSelectedItem In Me.lstSalAvailable.SelectedIndices
x = oSelectedItem.ToString()
AssignSamplePopulation(x)
Next
Catch ex As Exception
MsgBox(ex.Message & " " & ex.StackTrace)

Finally
' Enable save button
If Me.moSamplePopulationTypeList.IsDirty Then
Me.btnSalSave.Enabled = True
Else
Me.btnSalSave.Enabled = False
End If

Me.Cursor = Cursors.Default
End Try
End Sub

3.

Private Sub AssignSamplePopulation(ByVal index As Integer)
Dim oSamplePopulationType As CSamplePopulationType
Dim oProjectSampleType As CProjectSampleType

oSamplePopulationType = moSamplePopulationTypeList(index)

' add to assigned list
oProjectSampleType = Me.moProjectSampleTypeList.AddProjectSampleType

' Value indivudual properties
oProjectSampleType.ProjectID = moProject.ProjectID
oProjectSampleType.SPTypeID = oSamplePopulationType.SPTypeID
oProjectSampleType.GenericSalutationTemplate =
oSamplePopulationType.GenericSalutationDefault
oProjectSampleType.Description = oSamplePopulationType.Description
oProjectSampleType.CreatedBy =
CType(Thread.CurrentPrincipal.Identity,
SCS_Business_Layer.Security.CBusinessIdentity).Use rID
oProjectSampleType.LastModifiedBy =
CType(Thread.CurrentPrincipal.Identity,
SCS_Business_Layer.Security.CBusinessIdentity).Use rID

' remove from available list
moSamplePopulationTypeList.Remove(oSamplePopulatio nType)

'********** I tried this rebind below ......******************
' bind the available list
Me.lstSalAvailable.DataSource = moSamplePopulationTypeList
Me.lstSalAvailable.DisplayMember = "Description"
Me.lstSalAvailable.ValueMember = "SPTypeID"

' bind the assigned list
Me.lstSalAssigned.DataSource = moProjectSampleTypeList
Me.lstSalAssigned.DisplayMember = "Description"
Me.lstSalAssigned.ValueMember = "SPTypeID"

'************************************************* ***
Me.lstSalAssigned.Refresh()
Me.lstSalAvailable.Refresh()
End Sub

Similarly the unassign happens ....

Do let me know if you need more details

so.
say list 1 has following values 1, 2, 3, 4,5
list 2 has 7, 8
When I click value 2 and add it to list2, it sure does get added but a blank
line appears in list2. The value is invisible.Next, if I add value 3 to list2
then at this point value 2 which was added earlier becomes visible in list2
while the current value added which is 3 shows up as a invisible column.
"Phillip Williams" wrote:
If the dropdownlists were being databound before the custom lists were
updated then one would get the situation that you described. Can you post
the code that clarifies the sequence of events that affect these
dropdownlists.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"P K" wrote:

> Hi,
>
> I have two listboxes on my form.
> One has a list of available values while the other is a list of selected
> values.
> So I select a value from list 1 and add it to list 2 when "add" button is
> clicked.
> I can also select a value from list 2 and remove it on clicking "Remove"
> button, which would again add it to list 1.
>
> Now the lists are both bound to custom list objects. when I add or remove, I
> manipulate the list and then rebind it to the list boxes.
>
> The elements seem to get added but when I add element 1, a space is seen in
> list 2. When I add element 2, element 1 is visible while element 2 is not
> visisble. Same with remove.
> So in essence, everytime I add or remove an object for the first time, I
> cannot see the item in the list, though a blank row is seens. After every
> subsequent add or remove the previous element becomes visible.
>
> Any solutions please? Why can't the add and remove of items be seen
> instantly ?
>
> Thanks
>

Feb 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: N. Graves | last post by:
Hello... thank you for your time. I have a form that has a List box of equipotent records and a sub form that will show the data of the equipment select from the list box. Is it possible to...
3
by: gdbjohnson-AT-yahoo-dot-ca-nospamplz | last post by:
I have a ListBox built of a simple custom object for the ListItems used to be able to hold a Data Value, and a Display Value, with accessors for each. I have overridden the ToString method to...
1
by: Josema | last post by:
Hi to all, I have a class (persons) that derives from collection base: and another class (person) with this properties: -ID -Name When i have complete filled the object Persons with all...
0
by: Dave | last post by:
Hi all, I have a listbox that is complex bound by an arraylist. The problem is that when I delete an object from the arraylist, the listbox does not reflect those changes. I tried refreshing...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
1
by: Spock | last post by:
Hi. I have a form with a listbox and a few label fields all bound to a dataset. When i navigate the listbox the labels change accordingly. so far everything works good. I made a button to...
0
by: Tony Botelho | last post by:
I am fairly new to VB.NET and I am having some difficulty working with a bound listbox. On a simple form, I open a connection to my database and load a dataser. I then bind a listbox to the the...
1
by: erin.sebastian | last post by:
Hello Everyone, I have created a small application in vb.net to maintain items in a database the problem i am having is that once i delete/add/edit an individual item the changes don't reflect in...
5
by: JJ | last post by:
I want to have two lists (may have to be listboxes) on a page that are populated from a database. I then need to be able to click on an entry in one box and add it to the other, _preferably_...
1
by: sweetiecakes | last post by:
Hi I have a ListBox which is binded to a dataSet. When I need to refresh this dataSet, it works, but the old entries don't get removed from the listbox. Items.Clear() doesn't work when a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.