首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法获得组合框的选择值,返回空

无法获得组合框的选择值,返回空
EN

Stack Overflow用户
提问于 2014-02-09 22:04:38
回答 1查看 2.6K关注 0票数 2

我确信这在我的代码中确实是愚蠢的,但我无法从我的组合框中获得我生命中所选择的值。这是我的密码。

代码语言:javascript
复制
        Dim objScales As List(Of My.Scale) = Nothing
        Dim ExistingDimScale As Double = 0
        Dim ExistingDimScaleIndex As Double = 0

        _ScaleForm = New ScaleForm

        Try
            Me.LoadProperties()
            If Me.ConfigUnits <> 0 Then
                'Get the right scales per units
                If Me.ConfigUnits = 1 Then 'imperial
                    objScales = Me.GetImperialScales()
                Else
                    objScales = Me.GetMetricScales()
                End If
                'Load up the combobox values
                If objScales IsNot Nothing Then
                    _ScaleForm.cmbScale.DisplayMember = "Name"
                    _ScaleForm.cmbScale.ValueMember = "DimScale"
                    For Each objScale In objScales
                        _ScaleForm.cmbScale.Items.Add(objScale)
                        'MsgBox(objScale.Name.ToString)
                    Next

                    'Set the selected Index to the current dim scale
                    Double.TryParse(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("Dimscale").ToString, ExistingDimScale)
                    ExistingDimScaleIndex = objScales.FindIndex(Function(Val) Val.DimScale = ExistingDimScale)
                    If ExistingDimScaleIndex = -1 Then
                        _ScaleForm.cmbScale.SelectedIndex = 0
                    Else
                        Integer.TryParse(ExistingDimScaleIndex.ToString, _ScaleForm.cmbScale.SelectedIndex)
                    End If
                Else
                    MsgBox("There were no scales set")
                End If
            Else
                Throw New System.Exception("Error Reading Configuration Units")
            End If
        Catch ex As System.Exception
            MsgBox(ex.Message)
            'handle it here internally
        End Try

        _ScaleForm.ShowDialog()

        If DialogResult.OK = 1 Then
            MsgBox(_ScaleForm.cmbScale.SelectedValue)
        End If

最后一行MsgBox(_ScaleForm.cmbScale.SelectedValue)中的第二行,我想在这里使用所选的值来做一些事情,但是它总是在消息框中空出现。我很累,也不知道为什么不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-09 22:19:27

不是设置ComboBox的ComboBox属性,而是在item集合中逐个插入每个项。尝试设置DataSource

代码语言:javascript
复制
 _ScaleForm.cmbScale.DataSource = objScales

你会得到SelectedValue集。

另外,您可以读取SelectedItem属性,如果选择了某个对象,它将返回一个缩放对象,然后从这个实例中获取DimScale字段。

代码语言:javascript
复制
    if DialogResult.OK = _ScaleForm.ShowDialog() Then
        if _ScaleForm.cmbScale.SelectedItem IsNot Nothing Then
             My.Scale obj = CType(_ScaleForm.cmbScale.SelectedItem, My.Scale)
             ....
        End If
    End If
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21665671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档