我确信这在我的代码中确实是愚蠢的,但我无法从我的组合框中获得我生命中所选择的值。这是我的密码。
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)中的第二行,我想在这里使用所选的值来做一些事情,但是它总是在消息框中空出现。我很累,也不知道为什么不起作用。
发布于 2014-02-09 22:19:27
不是设置ComboBox的ComboBox属性,而是在item集合中逐个插入每个项。尝试设置DataSource
_ScaleForm.cmbScale.DataSource = objScales你会得到SelectedValue集。
另外,您可以读取SelectedItem属性,如果选择了某个对象,它将返回一个缩放对象,然后从这个实例中获取DimScale字段。
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 Ifhttps://stackoverflow.com/questions/21665671
复制相似问题