[英]how to make more than 2 column's in ListBox using C#?
如何在ListBox中创建超过2列,以及如何使用C#插入数据?
提前致谢
如以下VB.NET示例所示,使用UseCustomTabOffsets
和CustomTabOffsets
。
Public Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'ListBox1
'
Me.ListBox1.FormattingEnabled = True
Me.ListBox1.Location = New System.Drawing.Point(13, 13)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(248, 147)
Me.ListBox1.TabIndex = 0
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.ListBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.ListBox1.UseCustomTabOffsets = True
Me.ListBox1.CustomTabOffsets.AddRange(New Integer() {40, 40, 40})
Me.ListBox1.Items.Add("a" + vbTab + "b" + vbTab + "c")
End Sub
End Class
如果只想显示2个不同列中的数据,则yot可以合并两个列中的数据并添加到列表框中。
希望这有效!
为此,您将需要一个数据网格,因为列表框仅在每行显示一个元素。 但是首先您需要告诉我们您正在使用什么UI:Winforms,WPF,ASP.NET,Silverlight。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.