如何使用VB.NET将信息放入richtextbox中的列?

时间:2012-10-15 21:26:29

标签: vb.net

您好,我想在选择组合框中的项目时在richtextbox中显示三列。我想显示相应的演员年份,电影名称和电影列的数量。这就是我所拥有的:

Private Sub employeeComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles employeeComboBox.SelectedIndexChanged
    If employeeComboBox.SelectedItem Is "Sean Connery" Then
        historyTextBox.Text = ""
    ElseIf employeeComboBox.SelectedItem Is "George Lazenby" Then
        historyTextBox.Text = ""
    ElseIf employeeComboBox.SelectedItem Is "Roger Moore" Then
        historyTextBox.Text = ""
    ElseIf employeeComboBox.SelectedItem Is "Timothy Dalton" Then
        historyTextBox.Text = ""
    ElseIf employeeComboBox.SelectedItem Is "Pierce Brosnan" Then
        historyTextBox.Text = ""
    ElseIf employeeComboBox.SelectedItem Is "Daniel Craig" Then
        historyTextBox.Text = ""
    End If
End Sub

1 个答案:

答案 0 :(得分:1)

RichTextBox1.Text = "Row1 Col1" & vbTab & " Row1 Col2" & vbTab & "Row1 Col3" & vbCrLf &
  "Row2 Col1" & vbTab & " Row2 Col2" & vbTab & "Row2 Col3"

但是,我建议您使用DataGridView控件而不是RichTextBox,这样您就可以点击列标题按名称,年份等进行排序。

Dim dtb As New DataTable
dtb.Columns.Add("Year", GetType(String))
dtb.Columns.Add("Film", GetType(String))
dtb.Columns.Add("Actor", GetType(String))
dtb.Rows.Add("2001", "Film one", "Zac Black")
dtb.Rows.Add("2002", "Film two", "Young Green")
dtb.Rows.Add("2003", "Film three", "Xerxes Snifflehauser")
DataGridView1.AllowUserToAddRows = False
DataGridView1.AllowUserToDeleteRows = False
DataGridView1.DataSource = dtb