How To Update ListBox Selected Item In C#
In This C# Tutorial We Will See How To Display Selected Listbox Item Into TextBox And Edit It With A New Value From The TextBox Using CSharp Programming Language And .
Source Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class ListBox_Form : Form
{
public ListBox_Form()
{
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
textBox1.Text = listBox1.SelectedItem.ToString();
}catch
{
}
}
private void BTN_UPDATE_Click(object sender, EventArgs e)
{
int index = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(index);
listBox1.Items.Insert(index, textBox1.Text);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class ListBox_Form : Form
{
public ListBox_Form()
{
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
textBox1.Text = listBox1.SelectedItem.ToString();
}catch
{
}
}
private void BTN_UPDATE_Click(object sender, EventArgs e)
{
int index = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(index);
listBox1.Items.Insert(index, textBox1.Text);
}
}
}
=> OutPut :
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :