473,659 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting .Text property of a group of textboxes from another control

Hello,

I am trying to figure out how to efficiently do the following:

Say I have 10 TextBox fields on a form. From each of those, I would
like to have
a right click context menu. There are 10 menu items on the context
menu. Once
one of those items are selected, I would like the text to be copied
into the text field
of the appropriate textbox.

In the click Handler, I have something like:

private void myToolStripMenu Item_Click(obje ct sender, EventArgs e)

{
ToolStripMenuIt em m = (ToolStripMenuI tem)sender;
string mystr = m.Text;
// set the text field
}

Can someone tell me the c# construct to set the Text property of the
"calling" object, in this case a textbox?

Thanks
Mike
Jun 27 '08 #1
3 1418
On May 30, 2:54*pm, eljainc <elja...@sbcglo bal.netwrote:
Hello,

I am trying to figure out how to efficiently do the following:

Say I have 10 TextBox fields on a form. From each of those, I would
like to have
a right click context menu. There are 10 menu items on the context
menu. Once
one of those items are selected, I would like the text to be copied
into the text field
of the appropriate textbox.

In the click Handler, I have something like:

private void myToolStripMenu Item_Click(obje ct sender, EventArgs e)

* * * * {
* * * * * * ToolStripMenuIt em m = (ToolStripMenuI tem)sender;
* * * * * * string mystr = m.Text;
* * * * * * // set the text field

* * * * }

Can someone tell me the c# construct to set the Text property of the
"calling" object, in this case a textbox?
I'm sure there are probably more "elegant" ways to do it, but you
might want to consider some creative use of the ToolStripMenuIt em's
Tag property.
Jun 27 '08 #2
On Fri, 30 May 2008 11:54:35 -0700, eljainc <el*****@sbcglo bal.netwrote:
[...]
Can someone tell me the c# construct to set the Text property of the
"calling" object, in this case a textbox?
You can retrieve the control that caused the context menu to appear using
the ContextMenuStri p.SourceControl property (after getting the
ContextMenuStri p parent from the menu item, of course). Then, just set
the Text property of that Control instance.

Warning: there's a bug in .NET in which the SourceControl property is only
valid for top-level menu items. As long as you don't have sub-menus, this
won't be an issue. If you do, there are work-arounds...a Google search in
this newsgroup will help you find previous comments on that topic.

For what it's worth, your subject and your description of the control as
"the 'calling' object" both seem inaccurate to me, given what appears to
be the actual goal here. You may find that it's easier to get good
answers to your questions if you take care to make sure you've described
the question as simply, and non-prejudicially as possible (on the latter
point, I mean that the inaccurate parts I mentioned seem to be inaccurate
because of a presumption on your part as to what the solution might look
like, rather than simply stating the broader problem being solved).

Of course, I may have misunderstood the question, and if so then my
comments about the accuracy of the question may themselves be inaccurate.
However, even in that case there'd still be a good argument that the
question was ambiguous. :)

Pete
Jun 27 '08 #3

Pete, thanks! The ContextMenu.Sou rceControl property is just what I
needed.

Mike
Jun 27 '08 #4

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

Similar topics

21
9883
by: | last post by:
Hi, I am setting the NumericUpDown .Value property and the ValueChanged event is NOT being fired. Does this ONLY get fired when I change it on the UI and not programatically? Thanks
18
18359
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
1
6698
by: Martin | last post by:
Dear Group Sorry for bothering you again but I need expert advice on this. I have placed a HTML textbox on my aspx form and converted it to run as a server control. At some point in my code I assign a value to this textbox using Javascript with 'Form1.TextBox1.Value = "Hello"' But when I want to read the value of this Textbox later on using VB with 'MyVar = TextBox1.Text' it returns nothing.
1
3864
by: simon | last post by:
I have an unbound RTF2 control in an Access 2003 form which I set to show either unformatted text or else text with words and sentences highlighted. I do this by setting the PlainText property, getting back the rtfText and then adding the highlighting strings and resetting rtfText as below: sqry = "Select * from TextContent where FileID = " & ID Set rs = CurrentDb().OpenRecordset(sqry, dbOpenSnapshot) With rtfUnformatted ..rtfText = ""
1
5133
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
16
5137
by: mj.redfox.mj | last post by:
Can anyone help? I have a textbox which I'm programatically adding by using the following code: txtTest = New TextBox txtTest.ID = "txtLeft" + cntCount.ToString Page.FindControl("tdInput").Controls.Add(txtTest) This successfully creates a textbox called "txtLeft1" in the table
1
2587
by: fredd00 | last post by:
Hi I'm wondering in which class or interface the validationgroup property originates. i have created a web user control that uses the validation group property on textboxes, dropdownlist, validators etc.. the problem is that on my page i have to put 2 of those web user control when i submit one the other fails to validate
9
2201
pod
by: pod | last post by:
Hello I have a form which contains several textboxes and comboboxes I am able to loop through all the controls on this form and set the value (ctl.Text) to the Textboxes but if I try to set the datasource (ctl.DataSource), I get an error during the build. (when I type a DOT after ctl, I can see the Text property but not the Datasource one)
1
2026
by: berny.zamora | last post by:
Hello everyone, I have a composite control (lets call it the parent) that contains a datalist. The datalist has an ItemTemplate that contains another composite control (lets call it the child). I am trying to create a property at the parent control that sets a property in the child instances. So for example lets say I am creating a control that displays a list of hotel reservations for a group of people.
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8523
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8626
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.