Hope somebody can help!
I want to automatically be able to add code to the initialize routine on a Windows form when I add a custom control that I've written to a form.
Specifically, I'm trying to data bind to a normal class. So I've extended the standard text box to include a field for object name and property name. I want to be able to add a line such as :
controlname.Dat aBindings.Add(" Text", objectName, "myPropertyName ")
I've tried using google and looking at the documentation but can't seem to find this... I don't know if there is an alternative way of doing it in the startup code of the form (I seem to have a thought that reflection could be used to get the instance of the object for the data binding code above but I can't work out how!!).
I would be grateful for any pointers.
Many thanks in advance
Simon
Nov 20 '05
21 1906
sleep?? whats that????
Simon
"Michael Maes" <mi*****@merlot .com> wrote in message news:OA******** ******@TK2MSFTN GP11.phx.gbl...
Dont forget to sleep J
All the best and "play a lot" with the 'IComponentChan geService'. It's powerfull to use (but a hell to Debug...Since it's IDE)
Michael
"Simon Verona" <ne**@aphrodite uk.com> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Thanks Michael,
I think I'll sit down when I have a quiet few hours and play with this... I think I have to get to grip with the concepts that you have outlined.
I'll let you know how I get on!
Regards
Simon
"Michael Maes" <mi*****@merlot .com> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hey Simon,
Does this fully answer your questions, because I came to the conclusion I didn't point out how to actually set your binding.
On the other hand, I was thinking if your DataObjects are on the Form or ComponentTray, you could set the Binding in Design-time through the Property-Window. Sure your DataObjects must all inherit from the same BaseClass, so you could do something like:
Dim _DataSource As YourBaseClass
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Category("Data" ), _
Browsable(True) , _
Bindable(True), _
Description("Th e DataObject to bind the TextBox to."), _
TypeConverter(" System.Windows. Forms.Design.Da taSourceConvert er, System.Design") , _
RefreshProperti es(RefreshPrope rties.All)> _
Public Overloads Property DataSource() As Object
Get
Return _DataSource
End Get
Set(ByVal Value As Object)
_DataSource = Value
End Set
End Property
Should you use this approach, then you have to fine-tune this property, because it's for Complex-DataBinding and as you know, the TextBox-Class has Simple DataBinding. Doing this you would get a dropdown-list with all possible DataObjects your TextBox can bind to.
Anyway: should you furthermore want to make use of the 'IComponentChan geService' then you would defently need Reflection to Get/Set some values of Components/Controls which you don't know of in Design-Time. Something like:
Private Sub OnComponentRena me(ByVal sender As Object, ByVal ce As ComponentRename EventArgs)
If IsNothing(ce) Or IsNothing(ce.Co mponent) Then Exit Sub
Dim ot As Object = ce.Component
Dim s As String = ot.GetType.ToSt ring
Dim p As PropertyInfo
' Set a Boolean-Property
p = ot.GetType.GetP roperty("MyDesi redPropertyName ")
p.SetValue(ot, False, Nothing)
' Set a String-Property
p = ot.GetType.GetP roperty("MyOthe rDesiredPropert yName")
p.SetValue(ot, ce.NewName, Nothing)
' Continue other logic
............... ............... ............... ............
............... ............... ............... ............
End Sub
Also keep in mind with the 'IComponentChan geService' that you address the right INSTANCE, because if you have two or more controls of the same type on a form, then it will loop through all those controls (even if this service is called from within a single control)!!
I wish you the best, and let me know if you could manage your goal.
Kind regards,
Michael
"Simon Verona" <ne**@aphrodite uk.com> wrote in message news:uA******** ******@tk2msftn gp13.phx.gbl...
Michael,
Thanks very much for digging out the code.
Regards
Simon
J
"Simon Verona" <ne**@aphrodite uk.com> wrote in message news:On******** ******@TK2MSFTN GP10.phx.gbl...
sleep?? whats that????
Simon
"Michael Maes" <mi*****@merlot .com> wrote in message news:OA******** ******@TK2MSFTN GP11.phx.gbl...
Dont forget to sleep J
All the best and "play a lot" with the 'IComponentChan geService'. It's powerfull to use (but a hell to Debug...Since it's IDE)
Michael
"Simon Verona" <ne**@aphrodite uk.com> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Thanks Michael,
I think I'll sit down when I have a quiet few hours and play with this... I think I have to get to grip with the concepts that you have outlined.
I'll let you know how I get on!
Regards
Simon
"Michael Maes" <mi*****@merlot .com> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hey Simon,
Does this fully answer your questions, because I came to the conclusion I didn't point out how to actually set your binding.
On the other hand, I was thinking if your DataObjects are on the Form or ComponentTray, you could set the Binding in Design-time through the Property-Window. Sure your DataObjects must all inherit from the same BaseClass, so you could do something like:
Dim _DataSource As YourBaseClass
<EditorBrowsabl e(EditorBrowsab leState.Always) , _
Category("Data" ), _
Browsable(True) , _
Bindable(True), _
Description("Th e DataObject to bind the TextBox to."), _
TypeConverter(" System.Windows. Forms.Design.Da taSourceConvert er, System.Design") , _
RefreshProperti es(RefreshPrope rties.All)> _
Public Overloads Property DataSource() As Object
Get
Return _DataSource
End Get
Set(ByVal Value As Object)
_DataSource = Value
End Set
End Property
Should you use this approach, then you have to fine-tune this property, because it's for Complex-DataBinding and as you know, the TextBox-Class has Simple DataBinding. Doing this you would get a dropdown-list with all possible DataObjects your TextBox can bind to.
Anyway: should you furthermore want to make use of the 'IComponentChan geService' then you would defently need Reflection to Get/Set some values of Components/Controls which you don't know of in Design-Time. Something like:
Private Sub OnComponentRena me(ByVal sender As Object, ByVal ce As ComponentRename EventArgs)
If IsNothing(ce) Or IsNothing(ce.Co mponent) Then Exit Sub
Dim ot As Object = ce.Component
Dim s As String = ot.GetType.ToSt ring
Dim p As PropertyInfo
' Set a Boolean-Property
p = ot.GetType.GetP roperty("MyDesi redPropertyName ")
p.SetValue(ot, False, Nothing)
' Set a String-Property
p = ot.GetType.GetP roperty("MyOthe rDesiredPropert yName")
p.SetValue(ot, ce.NewName, Nothing)
' Continue other logic
............... ............... ............... ............
............... ............... ............... ............
End Sub
Also keep in mind with the 'IComponentChan geService' that you address the right INSTANCE, because if you have two or more controls of the same type on a form, then it will loop through all those controls (even if this service is called from within a single control)!!
I wish you the best, and let me know if you could manage your goal.
Kind regards,
Michael
"Simon Verona" <ne**@aphrodite uk.com> wrote in message news:uA******** ******@tk2msftn gp13.phx.gbl...
Michael,
Thanks very much for digging out the code.
Regards
Simon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rhy Mednick |
last post by:
I'm creating a custom control (inherited from UserControl) that is displayed
by other controls on the form. I would like for the control to disappear
when the user clicks outside my control the same way a menu does. To do
this my control needs to get notified when the user tried to click off of
it. The Leave and LostFocus events of the UserControl work most of the time
but not always. For example, if they click on a part of the form...
|
by: Jaikumar |
last post by:
Hi,
1) I have created one windows application, In the main form ( form1) i have added one usercontrol (usercontrol1), In that user control i am drawing one image.
2) In the UserControl1 i am showing one transparent form (form3) when ever user preseed left mouse button.
3) The form3 has one transparent user control (usercontrol2) that paints circles. That measn the circles will show on top the usercontrol1 image.
4) The form3 border style...
|
by: Harry |
last post by:
Hello,
I have a page with a RadioButtonList and a PlaceHolder control. The
RadioButtonList's AutoPostBack attribute is set to TRUE and its
SelectedIndexChanged event loads one of three UserControls into the
PlaceHolder's child control collection depending upon which of the three
radio buttons is selected. Each of the three UserControls have postback
events themselves triggered by button clicks. The problem I'm having is
keeping track of...
|
by: Matthew |
last post by:
All,
I have searched google and the newsgroups but can't find anything the
same as what I am experiencing (though I may have missed something).
I have controls (textboxes) within UserControls which are not behaving
as I would expect. Specifically, if there is a command button external
to the usercontrol which is activated by a shortcut key (eg Alt-B),
the command button Click event handler code 'executes' even though the
textbox set...
|
by: Gary Shell |
last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using.
I took the sample from that article and recreated the situation I see in my application. (Code included below.)
If you run the...
| |
by: Will Gillen |
last post by:
I know this has probably been asked before, but I can't seem to find a solid
answer in any of the archives. First, before my question, please forgive my
limited knowledge of the event lifecycle and page loading/rendering
lifecycle....
Ok, now for the question:
I have an ASPX page (page.aspx), and I have a UserControl (control.ascx).
The UserControl has one textbox on the control, and one button control.
I have added a public property...
|
by: JohnR |
last post by:
In it's simplest form, assume that I have created a usercontrol,
WSToolBarButton that contains a button. I would like to eventually create
copies of WSToolBarButton dynamically at run time based on some
initialization information obtained elsewhere. Basically, I'm going to
create my own dynamic toolbar where the toolbarbuttons can change. I'm not
using the VB toolbar because of limitations in changing things like
backcolor (I can't get...
|
by: MeowCow |
last post by:
I have created a UserControl that encapsulates a third party data grid.
My goal was to create my own DataSource and DataMember properties that
forward the binding to the third party grid, then use binding like
normal.
The problem I am running into is that my UserControl ends up with a
different BindingContext then the ParentForm it is contained in and
thus all other controls on the parent form. (I want various controls
on the form to...
|
by: Mark |
last post by:
Hi,
I'm new to ASP.Net, but not to c#, so I'm finding some things a little
wierd in this internet based world, especially passing data from page
to page.
I have created a UserControl to search for data. It will first be
displayed on the homepage of my website and then on a search results
page. When the page loads up, I want to be able to repopulate the
options that were first selected on the homepage.
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |