Dear readers,
i have a scheduler grouped by resources. I use a dropdown (selectionmode=Multisimple) to switch the resources on/off to show them side by side in the scheduler and AddHandler to each item in the dropdown.
In Form_Load() i use the following code
' Populates the dropdown
ddlResourcen.DataSource = SchedulerDataDataSet.ResourcesddlResourcen.ValueMember = "ID"ddlResourcen.DisplayMember = "Name"For Each item As RadListDataItem In Me.ddlResourcen.Items AddHandler item.RadPropertyChanged, AddressOf SelectedChangedNext
Here is the code for SelectedChanged()
Private Sub SelectedChanged() AddResources() End SubIt simply switch the resources on/off.
I can move appointment between resources, move and resize them and all is fine, until i try to save it to the database.
I use just the code suggested in the demos with just one change to show my resources in different colors at the last line
When i call the Sub UpdateDB the stored appointments/resources data is correct, but my handlers for to the drowdown items are not longer
working and just one resource is visible because my multi preselection is gone.
Private Sub UpdateDB() AppointmentsResourcesTableAdapter.Adapter.AcceptChangesDuringUpdate = False Dim deletedRelationRecords As schedulerDataDataSet.AppointmentsResourcesDataTable = TryCast(Me.SchedulerDataDataSet.AppointmentsResources.GetChanges(DataRowState.Deleted), schedulerDataDataSet.AppointmentsResourcesDataTable) Dim newRelationRecords As schedulerDataDataSet.AppointmentsResourcesDataTable = TryCast(Me.SchedulerDataDataSet.AppointmentsResources.GetChanges(DataRowState.Added), schedulerDataDataSet.AppointmentsResourcesDataTable) Dim modifiedRelationRecords As schedulerDataDataSet.AppointmentsResourcesDataTable = TryCast(Me.SchedulerDataDataSet.AppointmentsResources.GetChanges(DataRowState.Modified), schedulerDataDataSet.AppointmentsResourcesDataTable) Dim newAppointmentRecords As schedulerDataDataSet.AppointmentsDataTable = TryCast(Me.SchedulerDataDataSet.Appointments.GetChanges(DataRowState.Added), schedulerDataDataSet.AppointmentsDataTable) Dim deletedAppointmentRecords As schedulerDataDataSet.AppointmentsDataTable = TryCast(Me.SchedulerDataDataSet.Appointments.GetChanges(DataRowState.Deleted), schedulerDataDataSet.AppointmentsDataTable) Dim modifiedAppointmentRecords As schedulerDataDataSet.AppointmentsDataTable = TryCast(Me.SchedulerDataDataSet.Appointments.GetChanges(DataRowState.Modified), schedulerDataDataSet.AppointmentsDataTable) Try If newAppointmentRecords IsNot Nothing Then Dim newAppointmentIds As New Dictionary(Of Integer, Integer)() Dim oldAppointmentIds As New Dictionary(Of Object, Integer)() For i As Integer = 0 To newAppointmentRecords.Count - 1 oldAppointmentIds.Add(newAppointmentRecords(i), newAppointmentRecords(i).ID) Next AppointmentsTableAdapter.Update(newAppointmentRecords) For i As Integer = 0 To newAppointmentRecords.Count - 1 newAppointmentIds.Add(oldAppointmentIds(newAppointmentRecords(i)), newAppointmentRecords(i).ID) Next If newRelationRecords IsNot Nothing Then For i As Integer = 0 To newRelationRecords.Count - 1 newRelationRecords(i).AppointmentID = newAppointmentIds(newRelationRecords(i).AppointmentID) Next End If End If If deletedRelationRecords IsNot Nothing Then AppointmentsResourcesTableAdapter.Update(deletedRelationRecords) End If If deletedAppointmentRecords IsNot Nothing Then AppointmentsTableAdapter.Update(deletedAppointmentRecords) End If If modifiedAppointmentRecords IsNot Nothing Then AppointmentsTableAdapter.Update(modifiedAppointmentRecords) End If If newRelationRecords IsNot Nothing Then AppointmentsResourcesTableAdapter.Update(newRelationRecords) End If If modifiedRelationRecords IsNot Nothing Then AppointmentsResourcesTableAdapter.Update(modifiedRelationRecords) End If Me.SchedulerDataDataSet.AcceptChanges() Catch ex As Exception MessageBox.Show(String.Format("An error occurred during the update process:" & vbLf & "{0}", ex.Message)) Finally If deletedRelationRecords IsNot Nothing Then deletedRelationRecords.Dispose() End If If newRelationRecords IsNot Nothing Then newRelationRecords.Dispose() End If If modifiedRelationRecords IsNot Nothing Then modifiedRelationRecords.Dispose() End If End Try AddResources() End Sub Private Sub AddResources() Me.rscMain.Resources.Clear() Dim i As Integer = 0 For Each Row As DataRow In SchedulerDataDataSet.Tables("Resources").Rows Dim resource As New Resource() resource.Id = New EventId(i + 1) resource.Name = Row("Name").ToString resource.Color = Color.FromName(Row("SystemColor")) If ddlResourcen.Items(i).Selected = True Then Me.rscMain.Resources.Add(resource) End If i = i + 1 Next Me.rscMain.GroupType = GroupType.Resource Me.rscMain.ActiveView.ResourcesPerView = 4 End Sub
I belive this takes places because the SchedulerDataDataSet was changed, because when i reuse the code
' Populates the dropdownddlResourcen.DataSource = SchedulerDataDataSet.ResourcesddlResourcen.ValueMember = "ID"ddlResourcen.DisplayMember = "Name"For Each item As RadListDataItem In Me.ddlResourcen.Items AddHandler item.RadPropertyChanged, AddressOf SelectedChangedNexti can again use it, but my preselection is gone, of course.
Any suggestions how to stop this behaviour.
Kind regards
Martin Gartmann
