1

使用此代码,我可以填充我的列表视图:

foreach (string elements in Properties.Settings.Default.Items)
{
    ListViewItem lvi = new ListViewItem();

    var txt = elements;

    if (!listView1.Items.ContainsKey(txt))
    {
        lvi.Text = txt;


        lvi.Name = txt;

        lvi.SubItems.Add("");
        lvi.SubItems.Add("1.0");

        listView1.Items.Add(lvi);
    }
}

这是结果:

在此处输入图像描述

如何从文本框更改事件中仅更新第二列(总价)?(Windows 窗体,Visual Studio 2012)

4

1 回答 1

1

一些属性

        listView1.HideSelection = false;
        listView1.MultiSelect = false;
        listView1.FullRowSelect = true;
        listView1.View = View.Details;

我认为这就是你所要求的:

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        TextBox txt_sender = (TextBox)sender;

        if (listView1.SelectedItems.Count > 0)
        {
            listView1.SelectedItems[0].SubItems[1].Text = txt_sender.Text;
        }
    }

我还可以建议:(只允许数字和一个。)

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        TextBox txt_sender = (TextBox)sender;

        if (!char.IsControl(e.KeyChar) &&
            !char.IsDigit(e.KeyChar) &&
            !((e.KeyChar == '.') && !(txt_sender).Text.Contains('.')))
        {
            e.Handled = true;
        }
    }
于 2013-03-08T15:34:23.230 回答