473,511 Members | 16,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting ToolStripComboBox Text Property At Runtime...

Perhaps it is because it is the end of the day and my eyes are tired of
looking at code but I cannot seem to figure out what I am doing wrong and
what I can do (if anything) to fix it.

On a Windows form, I have a ToolStripComboBox object with a handful of
entries in the Items collection. I would like to change the text of the
ToolStripComboBox object (using the Text property) to something other than
the text of one of the items in the items collection. For example, if the
items in the Items collection were "Item A", "Item B", and "Item C", I would
like to be able to set the text to "Item Z". If I manually type the text in,
it works. If I set the Text property at runtime, the text remains to be that
of the currently selected item.

Any suggestions on how to get around this will be greatly appreciated.

Thank you,

Jason Richmeier
Mar 23 '06 #1
2 4872
I was a bit baffled when I grabbed a copy of your test project and it worked
as expected. This led me to believe that there was something different
between your project and mine.

In my project, I am using the SelectedIndexChanged event and it is in this
event where I am attempting to change the Text propery of the
ToolStripComboBox object. When I add this event handler to your test project
and attempt to set the Text property there, it behaves just like my project
does. From my observation (which may be inaccurate), it appears that the
Text property gets set to what I set it to and then it is set back to the
text of the drop down list item sometime after the event handler finishes
execution. I am not sure how to get around this.

If you have any more suggestions I would greatly appreciate it.

Thank you,

Jason Richmeier

""Jeffrey Tan[MSFT]"" wrote:
Hi Jason ,

Thanks for your post!

I have created a little test project regarding your issue, however, I can
manipulate the ToolStripComboBox.Text property at runtime without any
problem. Attached is the test project. You can download it with Outlook
Express, not IE.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights

Mar 24 '06 #2
Hi Jason ,

Thanks for your feedback!

Yes, with SelectedIndexChanged event, I can reproduce out this problem.

After doing some debugging, I think the problem stems from native Win32
combobox behavior. The native combobox sends us the CBN_SELCHANGE
notification (= SelectedIndexChanged event) using SendMessage rather than
PostMessage. So its quite possible that the native combo does extra stuff
on return from this call. Its also possible they simply ignore certain
changes that occur during this message. For example, setting text has no
effect, but changing the selected index does seem to work.

Regarding this issue, we can use Control.BeginInvoke method to queue
another delegate on the UI thread, then this delegate will execute after
the SelectedIndexChanged event, which works well in our scenario. Like this:

private void SetComboBoxTest()
{
this.toolStripComboBox1.Text += "test";
}
private void toolStripComboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
this.BeginInvoke(new MethodInvoker(SetComboBoxTest), null);
}
This works well in the sample project.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1958
by: Mike | last post by:
The following (C#) code snippet sets the text property of a label to null, then tests it for null, only to find out that is isn't. Can anyone explain why? Label1.Text = null; if (Label1.Text...
0
1583
by: Job Lot | last post by:
How can i bind ToolStripComboBox to a DataTable? There is no DataSource, DisplayMember & ValueMemeber property? Thanks
3
7553
by: bds | last post by:
Is there any way to databind a ToolStripComboBox? I have a form where I'd like a databound combobox to be the parameter selection of a DataGridView. This combobox comes from a table with your...
2
2155
by: MLH | last post by:
Combo box LimitToList property setting of No does not prevent the MS Access error "The text you enter must match an entry in the list" from popping up. What makes this bad is that the error is not...
1
1975
by: Frank Yamrick | last post by:
I am trying to program an application that requires a large number of screnes that are very similar in the respect that all the bottons and labels interact with each other with the same...
5
11454
by: Manuel | last post by:
How can I add an item to a ToolStripComboBox and specify a DisplayMember and a ValueMember?
1
6442
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
7
1994
by: Ronald S. Cook | last post by:
In a .NET Windows app, if I set somehting like the title of the form to "MyApp" at run-time, will that make the app run slightly slower than if I had set the title at design-time? Thanks, Ron
0
1216
by: McPolu | last post by:
Hello. I am trying to set ToolStripComboBox.DroppedDown inside of the Leave event and it does not work: public class MyToolStripComboBox : ToolStripComboBox { public MyToolStripComboBox() {...
0
7353
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.