COMBOBOX、TEXTBOX、LISTBOX问题

wll_lx 2003-03-28 10:34:16
当选中COMBOBOX中的品种后,在TEXTBOX中输入其单价,然后想在LISTBOX中显示COMBOBOX及TEXTBOX中的内容(一一对应如 CPU 1000元),不知如何解决?
如不用LISTBOX用什么好呢?该如何解决?
...全文
106 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qbilbo 2003-03-28
  • 打赏
  • 举报
回复
帮你写个了简单的代码。
使用方法:新建一个文本文档,将下面的代码贴入,再将文件后缀名改为frm,用VB打开即可。

VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 4860
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4860
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox txtPrice
Height = 315
Left = 3000
TabIndex = 0
Top = 180
Width = 1575
End
Begin VB.ComboBox cmbType
Height = 300
Left = 240
Style = 2 'Dropdown List
TabIndex = 1
Top = 180
Width = 1815
End
Begin MSComctlLib.ListView lvwList
Height = 1995
Left = 180
TabIndex = 2
Top = 780
Width = 4395
_ExtentX = 7752
_ExtentY = 3519
LabelWrap = -1 'True
HideSelection = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 0
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private CurrentID As Integer
Private F_LD As Boolean

Private Sub cmbType_Click()
Dim i As Integer

For i = 1 To lvwList.ListItems.Count
If lvwList.ListItems(i).Text = cmbType.Text Then
txtPrice.Text = lvwList.ListItems(i).SubItems(1)
txtPrice.SetFocus

CurrentID = i
Exit Sub
End If
Next

lvwList.ListItems.Add , , cmbType.Text
CurrentID = lvwList.ListItems.Count

txtPrice.Text = ""
If F_LD = False Then
txtPrice.SetFocus
End If
End Sub

Private Sub Form_Load()
cmbType.AddItem "CPU"
cmbType.AddItem "主板"
cmbType.AddItem "内存"
cmbType.AddItem "显卡"
cmbType.AddItem "声卡"

F_LD = True
cmbType.Text = "CPU"
F_LD = False

lvwList.ColumnHeaders.Add , , "货名", (lvwList.Width - 60) / 3
lvwList.ColumnHeaders.Add , , "价格", ((lvwList.Width - 60) / 3) * 2, 2
lvwList.View = lvwReport
End Sub

Private Sub txtPrice_Change()
lvwList.ListItems(CurrentID).SubItems(1) = txtPrice.Text
End Sub

Private Sub txtPrice_GotFocus()
If Len(txtPrice.Text) > 0 Then
txtPrice.SelStart = 0
txtPrice.SelLength = Len(txtPrice.Text)
End If
End Sub
mndsoft 2003-03-28
  • 打赏
  • 举报
回复
LISTBOX.AddItem COMBOBOX & format(TEXTBOX,"0.00")
qbilbo 2003-03-28
  • 打赏
  • 举报
回复
建议使用ListView控件。

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧