Created
August 17, 2020 06:51
-
-
Save jayu108/fdb0f83d99478d0aff18b702caf38601 to your computer and use it in GitHub Desktop.
C# -- listbox 에서 선택해제하기 (deselect)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Forms; | |
namespace listbox_deselect | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
this.listBox1.Items.Add(1); | |
this.listBox1.Items.Add(2); | |
this.listBox1.Items.Add(566); | |
this.listBox1.Items.Add("test"); | |
this.listBox1.Items.Add(5); | |
this.listBox1.Items.Add(337); | |
this.listBox1.Items.Add(64); | |
this.listBox1.Items.Add(7); | |
} | |
private void buttonSelect_Click(object sender, EventArgs e) | |
{ | |
//this.listBox1.SelectionMode = SelectionMode.One; | |
this.listBox1.SelectedIndex = 2; | |
} | |
private void buttonDeselect_Click(object sender, EventArgs e) | |
{ | |
//this.listBox1.SelectionMode = SelectionMode.None; | |
//this.listBox1.SelectedItem = null; | |
//this.listBox1.SelectedIndex = -1; | |
this.listBox1.BeginInvoke(new Action(() => | |
{ | |
//this.listBox1.SelectedItem = null; | |
this.listBox1.SelectedIndex = -1; | |
})); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment