Visual Basic 2010 Express - 向 ListView 添加项目 [英] Visual Basic 2010 Express - Adding Items to the ListView

查看:24
本文介绍了Visual Basic 2010 Express - 向 ListView 添加项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何简单地将项目添加到 ListView,同时将它们向下移动到索引中.我正在尝试添加三个项目;每列一项.ListView 由三列(日期、描述、长度)组成.我希望用户能够使用 TextBox 添加文本,然后使用Now"属性将日期添加到第一列,将 TextBox 的文本添加到 Description 列,然后让第三列使用长度"属性.

I want to know how to simply add items to the ListView while moving them down the index. I am trying to add three items; one item to each column. The ListView consists of three columns (Date, Description, Length). I want the user to be able to add text using a TextBox that will then add the date to the first column using the "Now" property, add the TextBox's text to the Description column, and then have the third column count the descriptions length using the "Length" property.

这听起来相当复杂,但我相信答案可能只是被忽视了.

It sounds rather complicated, but I am sure the answer may just be over-looked.

推荐答案

您可以按照自己的意愿格式化日期时间.只需将其放在按钮的 onclick 事件中,如果这是您正在使用的.

You can format the datetime how you would like. Just put that in your onclick event for your button, If that is what you are using.

c#:

private void button1_Click(object sender, EventArgs e)
{
    if (textBox1.Text == string.Empty) return;
    listView1.Items.AddRange( new[]
    {
        new ListViewItem(DateTime.Now.ToString()) , 
        new ListViewItem(textBox1.Text) , 
        new ListViewItem(textBox1.Text.Length.ToString())
    } );
    textBox1.Clear();
}

VB.NET:

Private Sub button1_Click(sender As Object, e As EventArgs)             
    If textBox1.Text = String.Empty Then
        Return
    End If
    listView1.Items.AddRange(New () {New ListViewItem(DateTime.Now.ToString()), New ListViewItem(textBox1.Text), New ListViewItem(textBox1.Text.Length.ToString())})
End Sub

这篇关于Visual Basic 2010 Express - 向 ListView 添加项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆