selectedindexchanged

How do I Change comboBox.Text inside a comboBox.SelectedIndexChanged event?

与世无争的帅哥 提交于 2020-01-02 06:14:10
问题 Code example: private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { if(some condition) { comboBox.Text = "new string" } } My problem is that the comboBox text always shows the selected index's string value and not the new string. Is the a way round this? 回答1: This code should work... public Form1() { InitializeComponent(); comboBox1.Items.AddRange(new String[] { "Item1", "Item2", "Item3" }); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { String

How do I Change comboBox.Text inside a comboBox.SelectedIndexChanged event?

∥☆過路亽.° 提交于 2020-01-02 06:12:34
问题 Code example: private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { if(some condition) { comboBox.Text = "new string" } } My problem is that the comboBox text always shows the selected index's string value and not the new string. Is the a way round this? 回答1: This code should work... public Form1() { InitializeComponent(); comboBox1.Items.AddRange(new String[] { "Item1", "Item2", "Item3" }); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { String

“SelectedIndexChanged” not firing after “Items.Clear()” in ListBox

我与影子孤独终老i 提交于 2019-12-23 07:47:15
问题 For a ListBox (With Selection mode set to One), I wish to track whether there's a selected item or none selected. To do so, I subscribed a method to SelectedIndexChanged and checked if the SelectedIndex is -1 or not. However, I noticed that the event doesn't fire after calling Items.Clear(), even though SelectedIndex changes to -1 (if it wasn't already -1). Why doesn't it fire? I know I can work around this by assigning -1 to SelectedIndex before clearing the list. But is there a better way?

Get the new value or index with SelectionChangeCommitted Event of DataGridView Combobox

删除回忆录丶 提交于 2019-12-23 04:21:23
问题 im using SelectionChangeCommitted to catch the event when a combobox selected index changed, but I can not get it's new value or index. private void ruleList_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (e.Control is ComboBox) { ComboBox comboBox = e.Control as ComboBox; comboBox.SelectionChangeCommitted += ruleListColumnComboSelectionChanged; } } private void ruleListColumnComboSelectionChanged(object sender, EventArgs e) { string value = ruleList

ASP.NET Dropdown List in Codebehind vs in ASPX page

戏子无情 提交于 2019-12-22 08:24:22
问题 I am generating a dropdown list in codebehind and cannot get the selectedindexchanged event to fire automatically. It works fine when put directly into the ASPX page, but I need it to be in the codebehind. This doesn't work: var deptList = new DropDownList { ID = "deptList", DataSource = departments, DataTextField = "deptname", DataValueField = "deptid", AutoPostBack = true, EnableViewState = true }; deptList.SelectedIndexChanged += new EventHandler(deptList_SelectedIndexChanged); deptList

select same index in list box

大城市里の小女人 提交于 2019-12-20 07:11:28
问题 I am making a website in asp.net and I have 2 list boxes: lbxPlayer1 and lbxPlayer2 lbxPlayer1.Items.Add("bob"); lbxPlayer1.Items.Add("jack"); lbxPlayer1.Items.Add("sam"); lbxPlayer2.Items.Add("fred"); lbxPlayer2.Items.Add("brian"); lbxPlayer2.Items.Add("dave"); they have both been populated with the same amount of values and i would like it so that when one of the lists is clicked the other list will select the same index. how do i do this? i assume the code would be in the lbxPlayer1

Dropdown OnSelectedIndexChanged not firing

烈酒焚心 提交于 2019-12-13 14:03:22
问题 The OnSelectedIndexChanged event is not firing for my dropdown box. All forums I have looked at told me to add the AutoPostBack="true" , but that didn't change the results. HTML: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="Current Time: " /><br /> <asp:Label ID="lblCurrent" runat="server" Text="Label" /><br /><br /> <asp:DropDownList ID="cboSelectedLocation"

Restore a drop down selected item after postback

落爺英雄遲暮 提交于 2019-12-13 13:28:18
问题 THE IDEA I'm trying to do a very simple thing - refresh page when an item of the drop down list is selected. Selected item of the dropdownlist is passed to the query string as a parameter. Page reloads. Then parameter is taken from query string and used to restore selection of the drop down list. Parameter keeps the value of the selected item. THE PROBLEM Real selected value is not passed to the query string parameter, it's always "0". DropDownList never gets last selected item, it always

ListBox.SelectedIndexChanged - can you determine if it was user initiated?

匆匆过客 提交于 2019-12-12 14:45:57
问题 My question is similar to this: How to prevent ListBox.SelectedIndexChanged event?, but I want to ask it a different way. Is there a simple way to determine if the 'SelectedIndexChanged' is coming from the user as opposed to initiated through code (e.g. ListBox.SelectedIndex = x)? 回答1: As far as I know, no, there's no simple way built-in. The best I've been able to do is set a flag just before changing it in code and then letting the event handler reset the flag and return. I suppose you

How can I immediately/reactively determine if any CheckedBoxListItem has been selected? [duplicate]

有些话、适合烂在心里 提交于 2019-12-11 10:11:51
问题 This question already has answers here : No ItemChecked event in a CheckedListBox? (4 answers) Closed 3 years ago . I want to enable a button only if valid criteria have first been selected (C# Windows Forms app). I have this code (I tried the IndexChanged and ValueChanged events first, but this answer indicates the ItemCheck event is the one to monitor: private void checkedListBoxUnits_ItemCheck(object sender, ItemCheckEventArgs iceargs) { buttonGenRpts.Enabled = ValidSelections(); } private