我想问一下如何将项目添加到组合框列表中。
现在,情况是这样的:我允许用户通过button
添加新作品,按下此button
后,将显示输入框,提示用户输入新工作人员&# 39;的名称,但我不知道如何使用新名称更新comboBox
列表中的项目。
comboBox
列表将包含所有工作人员。
这就是我所做的:
Dim new_worker As String
new_worker = Input Box("Enter the new worker's name :")
谢谢你能帮助我!
答案 0 :(得分:0)
首先,不应该使用inputbox,它只是简单的愚蠢。
其次,将文本添加到组合框
combobox1.items.add("an item text")
答案 1 :(得分:0)
要在组合框中插入项目,只需使用它的添加功能。
Combobox.items.add("The string of which you want to add")
如果您想使用输入框:
Dim responseFromUser as String = Inputbox(“Please Enter a item”,“这是输入框的标题”)
If responseFromUser <> "" then
Combobox.items.add(responseFromUser)
End If
答案 2 :(得分:0)
使用代码
combobox1.Items.Add(new_worker)
或
combobox1.Items.Add(InputBox("enter your string"))
答案 3 :(得分:0)
sub btn_click()
Dim str As String = InputBox("enter the name")
Dim com as new SqlCommand("insert into tbl values('" & str & "')",conn)
com.ExecuteNonQuery()
com=New SqlCommand("Select name from tbl",conn)
Dim da as new SqlDataAdapter(com)
Dim ds as New Dataset
da.Fill(ds)
Combobox1.datasource=ds.Tables(0)
Combobox1.DisplayMember="name"
Combobox1.ValueMember="name"
End Sub
Sub Form1_Load()
Dim com as SqlCommand=New SqlCommand("Select name from tbl",conn)
Dim da as new SqlDataAdapter(com)
Dim ds as New Dataset
da.Fill(ds)
Combobox1.datasource=ds.Tables(0)
Combobox1.DisplayMember="name"
Combobox1.ValueMember="name"
End Sub
答案 4 :(得分:0)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim name As String = InputBox("Enter a name")
ComboBox1.Items.Add(name)
ComboBox1.Sorted = True
End Sub
排序属性,以防您按字母顺序排序
答案 5 :(得分:0)
她是代码
Xml(文件名为Sample):
<?xml version="1.0" encoding="utf-8" ?>
<dataset>
<table></table>
</dataset>
Button_click:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim str As String = InputBox("enter the name")
Dim i As Integer
Dim ds As New DataSet
ds.ReadXml("C:\Documents and Settings\tech1.TECH01\My Documents\simple\simple\Sample.xml")
i = ds.Tables(0).Rows.Count
If str <> "" Then
ds.Tables(0).Columns.Add("col" & i)
Dim dr As DataRow = ds.Tables(0).NewRow
dr("col" & i) = str
ds.Tables(0).Rows.Add(dr)
ds.WriteXml("C:\Documents and Settings\tech1.TECH01\My Documents\simple\simple\Sample.xml", XmlWriteMode.IgnoreSchema)
End If
ComboBox2.Items.Clear()
If ds.Tables(0).Rows.Count > 1 Then
For i = 1 To ds.Tables(0).Rows.Count - 1
ComboBox2.Items.Add(ds.Tables(0).Rows(i)("col" & i).ToString)
Next
End If
End Sub
Form_load中:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ds As New DataSet
Dim i As Integer
ds.ReadXml("C:\Documents and Settings\tech1.TECH01\My Documents\simple\simple\Sample.xml") 'your xml file's path
ComboBox2.Items.Clear()
If ds.Tables(0).Rows.Count > 1 Then
For i = 1 To ds.Tables(0).Rows.Count - 1
ComboBox2.Items.Add(ds.Tables(0).Rows(i)("col" & i).ToString)
Next
End If
End Sub