Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 4-Feb-13 3:41am
vidkaat506
Edited 4-Feb-13 3:55am
CHill6044K
v2
Comments
CHill60 at 4-Feb-13 9:55am
   
what's the problem?
Sandeep Mewara at 4-Feb-13 9:57am
   
And the issue is?
vidkaat at 4-Feb-13 10:02am
   
This allows me to select multiple checkbos.But i need to restrict it to one checkbox click.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
I have added an validation in ItemChecked event.
 
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
  Permalink  
v4
Comments
vidkaat at 4-Feb-13 10:32am
   
How do i do that .Just copy paste or create one from the designer.Please help. Thanks.
Muthuraja Irullandi at 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 at 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 at 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 at 4-Feb-13 11:16am
   
Hi, Now I have added an logic into ItemCheck event, please check the updated solution
vidkaat at 4-Feb-13 11:32am
   
Thanks for ur reply.What is the newValue means? I am sorry to bother u so many times.
vidkaat at 4-Feb-13 11:35am
   
I got it.Thanks.Works perfect for me. Thank u so much. Appreciate your time
Muthuraja Irullandi at 4-Feb-13 11:39am
   
Thats, great, I have also modified the solution for vb.NET
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v3
Comments
vidkaat at 4-Feb-13 10:03am
   
i did that but it does not work.
Marcus Kramer at 4-Feb-13 10:11am
   
Web or Windows.Forms?
vidkaat at 4-Feb-13 10:12am
   
windows.forms

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Guruprasad.K.Basavaraju 450
1 Sergey Alexandrovich Kryukov 370
2 Shai Vashdi 318
3 OriginalGriff 265
4 Peter Leow 171
0 Sergey Alexandrovich Kryukov 9,109
1 OriginalGriff 5,290
2 Peter Leow 4,010
3 Maciej Los 3,535
4 Abhinav S 3,263


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid