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