更新第二列的ListView从文本框改变 - C# [英] Update second column listView from TextBox changed - c#

查看:106
本文介绍了更新第二列的ListView从文本框改变 - C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有了这个code,我可以填充我的ListView:

With this code I can populate my listview:

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)

How can I update only second column(Total Price) from textbox changed event? (Windows Forms, Visual Studio 2012)

推荐答案

某些属性。

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

我想这是你所要求的:

I think this is what you are asking for:

    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;
        }
    }

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

May I also suggest: (only allow numbers and one .)

    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;
        }
    }

这篇关于更新第二列的ListView从文本框改变 - C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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