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);
}
}
this is result:
How can I update only second column(Total Price) from textbox changed event? (Windows Forms, Visual Studio 2012)
Some properties
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;
}
}