Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VB
Private Sub btnContinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnContinue.Click
        'Private Sub btnContinue_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles btnContinue.Click
        Dim lvi As ListViewItem = Nothing
       
        Dim _optionsHTML As String = "<ul>"
        Dim _options As String = ""
        Dim i As Integer = 0

        For Each lvi In lvCancellationOptions.Items
            

            If lvi.Checked Then

                _optionsHTML &= "<li>" & lvi.Text & "</li>"
                _options &= lvi.Text & vbCrLf
                i += 1

            End If

        Next

        _optionsHTML &= "</ul>"

        If (i = 0) Then

            MessageBox.Show("You must select at least one cancellation option")

        Else

            RaiseEvent ContinueCancellation(True, _optionsHTML, _options)
            Me.Close()

        End If

    End Sub
Posted
Updated 4-Feb-13 3:55am
v2
Comments
CHill60 4-Feb-13 9:55am    
what's the problem?
Sandeep Mewara 4-Feb-13 9:57am    
And the issue is?
vidkaat 4-Feb-13 10:02am    
This allows me to select multiple checkbos.But i need to restrict it to one checkbox click.

System.Windows.Forms solution: Set the Multiselect property to false for the ListView control.
System.Web.UI.WebControls solution: Add a javascript function to handle the selection changed event on the checkbox controls generated in the html and then simply clear all the other checkboxes in that function. Using jquery would make things much easier.
 
Share this answer
 
v3
Comments
vidkaat 4-Feb-13 10:03am    
i did that but it does not work.
fjdiewornncalwe 4-Feb-13 10:11am    
Web or Windows.Forms?
vidkaat 4-Feb-13 10:12am    
windows.forms
Hi,
I have added an validation in ItemChecked event.
VB
Private Sub lvCancellationOptions_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles lvCancellationOptions.ItemCheck
        If (lvCancellationOptions.CheckedItems.Count > 0 And e.NewValue = CheckState.Checked) Then

            Dim item As ListViewItem = lvCancellationOptions.CheckedItems(0)
            item.Checked = False
        End If
    End Sub



Best Regards
Muthuraja
 
Share this answer
 
v4
Comments
vidkaat 4-Feb-13 10:32am    
How do i do that .Just copy paste or create one from the designer.Please help.

Thanks.
Muthuraja Irullandi 4-Feb-13 10:37am    
Hi,
In the form, select the listview control, in the property windows, select the events, and double click in the Item_Checked event.

I am modifying the code with your control name. Please see the updated solution and copy that code in your event.

Let me know any issues
vidkaat 4-Feb-13 10:50am    
Thanks.It do work but wat would happen if the user selects a wrong one. So is there logic like if he clicks the second option the forst one should be unchecked.

Appreciate your help.
Thanks.
vidkaat 4-Feb-13 10:45am    
Thanks.It do work but wat would happen if the user selects a wrong one. So is there logic like if he clicks the second option the forst one should be unchecked.

Appreciate your help.
Thanks.
Muthuraja Irullandi 4-Feb-13 11:16am    
Hi,
Now I have added an logic into ItemCheck event, please check the updated solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900