我希望vb.net代码允许用户在listview项目中只选择一个选项, [英] I want vb.net code to allow users to select only one option in the listview item,

查看:323
本文介绍了我希望vb.net代码允许用户在listview项目中只选择一个选项,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 私有  Sub  btnContinue_Click( ByVal  sender  As  System。 Object  ByVal  e  As  System.EventArgs)句柄 btnContinue.Click 
< span class =code-comment>' Private Sub btnContinue_Click(ByVal sender As System.Object,ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs)处理btnContinue.Click
Dim lvi As ListViewItem = 没什么

Dim _optionsHTML As String = < ul>
Dim _options As < span class =code-keyword> String =
< span class =code-keyword> Dim i As 整数 = 0

对于 每个 lvi lvCancellationOptions.Items


如果 lvi.Checked 然后

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

结束 如果

下一步

_optionsHTML& = < / ul>

If (i = 0 然后

MessageBox.Show(< span class =code-string> 您必须至少选择一个取消选项

Else

RaiseEvent ContinueCancellation( True ,_ optionsHTML,_options)
.Close()

结束 如果

结束 Sub

解决方案

System.Windows.Forms解决方案:为ListView控件设置Multiselect属性为false。

System.Web.UI.WebControls解决方案:添加一个javascript函数处理html中生成的复选框控件上的选择更改事件,然后只清除该函数中的所有其他复选框。使用jquery会让事情变得更容易。




我在ItemChecked事件中添加了验证。

 私有  Sub  lvCancellationOptions_ItemCheck( ByVal  sender  As  System。 Object  ByVal  e  As  System.Windows.Forms.ItemCheckEventArgs)句柄 lvCancellationOptions.ItemCheck 
如果(lvCancellationOptions.CheckedItems.Count> 0 e .NewValue = CheckState.Checked)然后

Dim item As ListViewItem = lvCancellationOptions.CheckedItems( 0 )
item.Checked = False
结束 如果
结束 Sub







最好的问候

Muthuraja


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

解决方案

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.


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


这篇关于我希望vb.net代码允许用户在listview项目中只选择一个选项,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆