A menu is installed on the form - the MenuStrip component, on this menu ToolStripComboBox is created. By clicking on any element of the ToolStripComboBox collection, the SelectedIndexChanged event is generated, some code is processed and the value of the selected element is assigned to the Text property of this ToolStripComboBox.

Question: how to make the code to be processed by clicking, but the Text property remains unchanged.

Like that:

/* На Ρ„ΠΎΡ€ΠΌΠ΅ Π΅ΡΡ‚ΡŒ мСню MenuStrip с ΠΈΠΌΠ΅Π½Π΅ΠΌ: mGlv Π² Π½Π΅ΠΉ создан элСмСнт ToolStripComboBox - cmBx */ private void cmBx_SelectedIndexChanged(object sender, EventArgs e) { /* По ΠΊΠ»ΠΈΠΊΡƒ Π½Π° ΠΎΠ΄Π½ΠΎΠΌ ΠΈΠ· элСмСнтов ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ срабатываСт ΠΎΠΏΡ€Π΅Π΄Π΅Π»Ρ‘Π½Π½Ρ‹ΠΉ ΠΊΠΎΠ΄ Π½Π΅ Π²Π°ΠΆΠ½ΠΎ ΠΊΠ°ΠΊΠΎΠΉ. Π”Π°Π»Π΅Π΅ - имя элСмСнта ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ cmBx, ΠΏΠΎ ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌΡƒ ΠΊΠ»ΠΈΠΊΠ½ΡƒΠ»ΠΈ ΠΏΠ΅Ρ€Π΅Ρ…ΠΎΠ΄ΠΈΡ‚ Π² Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ Π΄Π°Π½Π½ΠΎΠ³ΠΎ cmBx, Ρ‚.Π΅. cmBx.Text ΠΏΡ€ΠΈΠΎΠ±Ρ€Π΅Ρ‚Π°Π΅Ρ‚ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΈΠΌΠ΅Π½ΠΈ Π²Ρ‹Π±Ρ€Π°Π½Π½ΠΎΠ³ΠΎ элСмСнта, Π° трСбуСтся Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ cmBx Ρ‚.Π΅ свойство cmBx.Text ΠΎΡΡ‚Π°Π²Π°Π»ΠΎΡΡŒ Π½Π΅ΠΈΠ·ΠΌΠ΅Π½Π½Ρ‹ΠΌ всСгда */ } 
  • I made the same form, picked it up and came to the conclusion that the only way here is to set the cmBx.Text property to the initial value manually after the completion of the code execution. - Jembo_by

1 answer 1

The question is poorly understood. Give an example code.

From what I understand, I advise you to add a line

 comboBox1.SelectedItem = null; 

Or this:

 cls.frm2.comboBox1.SelectedText = null; 

In the first case, the selection is removed from the combobox, and in the second, the text is simply removed (the first option includes the second).