PeterErhard
asked on
CheckedListBox on Tab Control
I've got another strange problem with the CheckedListBox control which I have showing on a Tab Control. When I check a few items, switch it another tab and switch back the CheckedListBox has reset itself and lost the selections I made.
Isn't the CheckedListBox supported within the Tab Control? Or....?
Isn't the CheckedListBox supported within the Tab Control? Or....?
if the are bound controles try updating the dataset before switching to another tab
ASKER
Thanks for your response David.
Problem being is that if the user selects a few options on the CheckedListBox I don't want to save until these options to the database until the save button is clicked. Is there anyway around that?
Problem being is that if the user selects a few options on the CheckedListBox I don't want to save until these options to the database until the save button is clicked. Is there anyway around that?
ASKER
Anyone?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for that - turns out it's a bug with VB.net - not fixed in the service pack either.
I've got it working with this but now it turns out my saving and loading isn't working because I'm no longer using a dataset.
Private Function LoadEthnicGroups() As Boolean
Dim cmd As SqlCommand = cnn.CreateCommand
cmd.CommandType = CommandType.StoredProcedur e
cmd.CommandText = "procLoadEthnicGroupOption s"
Dim reader As SqlDataReader = cmd.ExecuteReader
While reader.Read
With reader
ListBox_EthnicGroup.Items. Add(.GetVa lue(.GetOr dinal("Eth nicGroup") ))
ListBox_EthnicGroup.Items. IndexOf(.G etValue(.G etOrdinal( "LookUp_Et hnicGroupI DAuto")))
End With
End While
reader.Close()
LoadEthnicGroups = True
End Function
I can't believe what a pain in the arse this CheckedListBox control is. Do you know what I can replace this line of the code with - ItemIndex = CType(ListBox_EthnicGroup. Items(Coun t), DataRowView)("LookUp_Ethni cGroupIDAu to") ?
Private Function LoadClientEthnicGroup() As Boolean
Dim EthnicGroupCount As Integer, EthnicGroupIDAuto As Integer
Dim ItemIndex As Object, Count As Integer
Try
'Get Number of Ethnic Group Items in ListBox
EthnicGroupCount = ListBox_EthnicGroup.Items. Count()
Dim cmd As SqlCommand = cnn.CreateCommand
cmd.CommandType = CommandType.StoredProcedur e
cmd.CommandText = "procLoadClientEthnicGroup Options"
cmd.Parameters.Add(New SqlParameter("@ClientIDAut o", SqlDbType.Int, 4))
cmd.Parameters("@ClientIDA uto").Valu e = 1
Dim dr As SqlDataReader = cmd.ExecuteReader
While dr.Read
With dr
EthnicGroupIDAuto = CInt(.GetValue(.GetOrdinal ("EthnicGr oupIDAuto" )))
'Find out the Index for the EthnicGroupIDAuto Saved
'And check the item
For Count = 0 To EthnicGroupCount - 1
'ItemIndex = CType(ListBox_EthnicGroup. Items(Coun t), DataRowView)("LookUp_Ethni cGroupIDAu to")
'ItemIndex = CType(ListBox_EthnicGroup. Items(Coun t), CheckedListBox.SelectedInd exCollecti on)
'ItemIndex = CType(ListBox_EthnicGroup. Items(Coun t), CheckedListBox.SelectedInd exCollecti on)
If CInt(EthnicGroupIDAuto) = CInt(ItemIndex) Then
ListBox_EthnicGroup.SetIte mChecked(C ount, True)
End If
Next
End With
End While
dr.Close()
LoadClientEthnicGroup = True
Catch ex As Exception
MessageBox.Show(Err.Descri ption)
End Try
End Function
and the same here:
Private Function SaveClientEthnicGroup() As Boolean()
Try
Dim Index As Integer
Dim cmdDelete As New Data.SqlClient.SqlCommand( "Delete from ClientIDAuto_EthnicGroupID Auto where ClientIDAuto = " & m_ClientNumber, cnn)
cmdDelete.ExecuteNonQuery( )
Dim cmdInsert As New Data.SqlClient.SqlCommand( "Insert into ClientIDAuto_EthnicGroupID Auto (ClientIDAuto, EthnicGroupIDAuto) Values (@ClientIDAuto, @EthnicGroupIDAuto)", cnn)
cmdInsert.Parameters.Add(" @ClientIDA uto", m_ClientNumber)
cmdInsert.Parameters.Add(" @EthnicGro upIDAuto", SqlDbType.Int)
For Each Index In ListBox_EthnicGroup.Checke dIndices
cmdInsert.Parameters("@Eth nicGroupID Auto").Val ue = CType(ListBox_EthnicGroup. Items(Inde x), DataRowView)("LookUp_Ethni cGroupIDAu to")
cmdInsert.ExecuteNonQuery( )
Next
Catch ex As Exception
MessageBox.Show(Err.Descri ption)
End Try
End Function
I've got it working with this but now it turns out my saving and loading isn't working because I'm no longer using a dataset.
Private Function LoadEthnicGroups() As Boolean
Dim cmd As SqlCommand = cnn.CreateCommand
cmd.CommandType = CommandType.StoredProcedur
cmd.CommandText = "procLoadEthnicGroupOption
Dim reader As SqlDataReader = cmd.ExecuteReader
While reader.Read
With reader
ListBox_EthnicGroup.Items.
ListBox_EthnicGroup.Items.
End With
End While
reader.Close()
LoadEthnicGroups = True
End Function
I can't believe what a pain in the arse this CheckedListBox control is. Do you know what I can replace this line of the code with - ItemIndex = CType(ListBox_EthnicGroup.
Private Function LoadClientEthnicGroup() As Boolean
Dim EthnicGroupCount As Integer, EthnicGroupIDAuto As Integer
Dim ItemIndex As Object, Count As Integer
Try
'Get Number of Ethnic Group Items in ListBox
EthnicGroupCount = ListBox_EthnicGroup.Items.
Dim cmd As SqlCommand = cnn.CreateCommand
cmd.CommandType = CommandType.StoredProcedur
cmd.CommandText = "procLoadClientEthnicGroup
cmd.Parameters.Add(New SqlParameter("@ClientIDAut
cmd.Parameters("@ClientIDA
Dim dr As SqlDataReader = cmd.ExecuteReader
While dr.Read
With dr
EthnicGroupIDAuto = CInt(.GetValue(.GetOrdinal
'Find out the Index for the EthnicGroupIDAuto Saved
'And check the item
For Count = 0 To EthnicGroupCount - 1
'ItemIndex = CType(ListBox_EthnicGroup.
'ItemIndex = CType(ListBox_EthnicGroup.
'ItemIndex = CType(ListBox_EthnicGroup.
If CInt(EthnicGroupIDAuto) = CInt(ItemIndex) Then
ListBox_EthnicGroup.SetIte
End If
Next
End With
End While
dr.Close()
LoadClientEthnicGroup = True
Catch ex As Exception
MessageBox.Show(Err.Descri
End Try
End Function
and the same here:
Private Function SaveClientEthnicGroup() As Boolean()
Try
Dim Index As Integer
Dim cmdDelete As New Data.SqlClient.SqlCommand(
cmdDelete.ExecuteNonQuery(
Dim cmdInsert As New Data.SqlClient.SqlCommand(
cmdInsert.Parameters.Add("
cmdInsert.Parameters.Add("
For Each Index In ListBox_EthnicGroup.Checke
cmdInsert.Parameters("@Eth
cmdInsert.ExecuteNonQuery(
Next
Catch ex As Exception
MessageBox.Show(Err.Descri
End Try
End Function