问题描述
我正在使用一个名为个人祖先文件的程序,并喜欢他们用于添加或更新信息的设置。他们有一列(第1列),名称是数据库的列(全名,出生数据,死亡日期等等),然后第二列是您输入信息的地方,例如,
I was using a program called personal ancestry file and liked the setup they had for adding or updating information. They had one column (1st) with the name the columns of a database (full name, data of birth, date of death, ....etc) then the second column was where you entered the information, for instance,
column 1 column 2
Full name: Smith, Steve
Date of birth: 12/12/2012
Date of death: 12/12/2017
设计很有趣,而且流量很大。它只显示了我所在列的文本框或组合框。我可以选中或使用鼠标转到我想要的任何列。一旦我离开一列然后转到下一列,文本框或组合框就会消失并显示在新列中。
我可以将文本框添加到列表视图的特定位置,但是,它会将其永久添加到列表视图中,而不是仅在列或单元格上显示时才显示。该代码是:
the design is interesting and the flow is great. it only showed a textbox or combobox for which ever column I was in. I could tab over or use my mouse to go to whichever column I wanted to. once I left one column and went to the next then the textbox or combobox would disappear and be displayed in the new column.
I can add a textbox to the specific location of a listview, however, it permanently adds it to the listview instead of being displayed only when on that column or cell. that code is:
Private Sub ListView1_MouseDoubleClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseClick
For i = 0 To ListView1.Items.Count - 1
With txb
.Name = ListView1.Items(i).Text.ToString.Replace(":", "")
End With
Next
txb.Location = New Point(ListView1.SelectedItems.Item(0).SubItems.Item(1).Bounds.X, ListView1.SelectedItems.Item(0).SubItems.Item(1).Bounds.Y)
ListView1.Controls.Add(txb)
ListView1.SelectedItems.Item(0).SubItems.Item(1).Text = txb.Text
If Not String.IsNullOrEmpty(ListView1.Items(0).SubItems(1).Text) Then
txb.Hide()
Else
txb.Clear()
txb.Show
End If
End Sub
我的尝试:
我试图使用listview.controls.remove(txb),但这并不像我想要的那样工作。
我现在尝试了hide / show方法。它是半成品。问题是当我第一次移动到另一个子项时,文本被添加到它而不是我试图添加文本的那个。我遇到的另一个问题是使用txb.clear,我希望在转到子项目之前我可以重复使用子项单元格中的文本并清除文本框中的文本数据。
有什么建议吗?
What I have tried:
I have tried to use a listview.controls.remove(txb), but that did not work the way I wanted it to.
I have now tried the hide/show method. It semiworks. Problem is when I first move to another subitem the text gets added to it instead of the one I was trying to add text to. Another issue I am having is with the txb.clear, I was hoping that I could reuse the text in the subitem cell and clear text data in the textbox before going to the subitem.
Any suggestions?
推荐答案
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim a As ListViewItem
a = Me.ListView1.Items.Add("One")
a.SubItems.Add("1")
a = Me.ListView1.Items.Add("Two")
a.SubItems.Add("2")
a = Me.ListView1.Items.Add("Three")
a.SubItems.Add("3")
End Sub
Private Sub ListView1_Click(sender As Object, e As EventArgs) Handles ListView1.Click
If Not txb Is Nothing Then
RemoveHandler txb.Leave, AddressOf txb_Leave
ListView1.Controls.Remove(txb)
txb.Hide()
txb = Nothing
End If
txb = New TextBox()
txb.Text = Me.ListView1.SelectedItems(0).SubItems(1).Text
txb.Location = New Point(ListView1.SelectedItems.Item(0).SubItems.Item(1).Bounds.X, ListView1.SelectedItems.Item(0).SubItems.Item(1).Bounds.Y)
txb.Tag = Me.ListView1.SelectedItems(0)
AddHandler txb.Leave, AddressOf txb_Leave
ListView1.Controls.Add(txb)
End Sub
Private Sub txb_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
Dim item As ListViewItem
item = CType(txb.Tag, ListViewItem)
item.SubItems(1).Text = txb.Text
End Sub
这篇关于如何在listview中放置临时组合框或文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!