【问题标题】:How to get pre-selected combo box value from combo box?如何从组合框中获取预选的组合框值?
【发布时间】:2018-03-25 07:31:24
【问题描述】:

在这里你可以看到我没有使用combox_click,因为它是在上面声明的,而当前是另一个无需点击即可调用的函数,这里我的问题是如何从组合框中获取预选值而不点击框?

   Public Sub ComDep_Change()
        Dim sQuery As String
        Dim oRS As New ADODB.Recordset
        Dim rsPR As New ADODB.Recordset
        Dim dateFormat As String
        Dim sPONO As String
        Dim sPOAmt As String
        'oRS.Open "po_receiveable", PRCnn, adOpenDynamic, adLockOptimistic
        combVal = ComDep.List(ComDep.ListIndex)
        If Not combVal = "ALL_DEPT" And frmMain.OptLatestCN.Value = True Then
            'MsgBox ("Works")
            dateFormat = "#" + CStr(Day(Now)) + "/" + CStr(Month(Now)) + "/" + CStr(Year(Now) - 3) + "#"
            sQuery = "select * from CN_Request_Header where dept = '" & combVal & "' and requestdate >= " & dateFormat & ""
    '        sQuery = "Select PO_No, PO_Requestor, PO_Req_Dept, PO_Status, PO_Approval_M, PO_Approval_GM, PO_Approval_D, PO_HRApproval, VC_No, TH_Sup_Inv, PO_HR_Rmk, PO_Req_Date, PO_SupplierName, PO_OverallAmt from PR_INFO where PO_Req_Dept = '" & combVal & "'"
    '        MsgBox ("Result" & sQuery)
            rsPR.Open sQuery, PRCnn, adOpenDynamic, adLockOptimistic
            lvwCreditNote.ListItems.Clear

            Do While Not rsPR.EOF
            Set listitem = frmMain.lvwCreditNote.ListItems.Add
            With listitem
                .Text = CStr(Trim(rsPR!requestID))
                .SubItems(1) = Trim(rsPR!requestID)
                .SubItems(2) = Format(CStr(rsPR!requestdate), "dd-mmm-yy")
                .SubItems(3) = Trim(rsPR!createby)
                .SubItems(4) = Trim(rsPR!dept)
                .SubItems(5) = Trim(rsPR!reqstatus)
                If IsNull(rsPR!custName) Then
                    .SubItems(6) = ""
                Else
                    .SubItems(6) = Trim(rsPR!custName)
                End If
                If IsNull(rsPR!cnamt) Then
                    .SubItems(7) = "0.00"
                Else
                    .SubItems(7) = Format(rsPR!cnamt, "#,###,##0.00")
                End If

【问题讨论】:

  • ComDep.Text 怎么样?

标签: combobox vb6


【解决方案1】:

您将在组合框中获得当前 SELECTED 元素 通过使用 SELECTEDINDEX 属性

如果未选择任何内容,那么您将获得返回给您的值 -1。 如果选择了某些内容,它将在 0 到 Combox.Count - 1

的范围内

获取所选项目的文本 你可以使用类似...

Dim SelIndex as Integer
Dim SelText As String
'
SelIndex = MyCombobox.SelectedIndex
If (SelIndex >= 0) AND (SelIndex <= MyCombobox.Count - 1) Then
   SelText = MyCombobox.List(Index)
Else
   'Nothing was selected in the combobox
End If

【讨论】:

  • 嗨@Zeddy,感谢您联系我的帖子,您确定SelectedIndex 在VB6 中有效吗?我试过了,还是不行。
猜你喜欢
  • 1970-01-01
  • 2018-12-04
  • 1970-01-01
  • 2013-10-25
  • 2013-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多