Hello,
I have 3 textboxes and 1 combobox on a form. On entering the control I want
to select all the text. I can make an array of textboxes like this:
Dim arrTxt As TextBox() = {txt1, txt2, txt3}
Then I loop through that array
Private Sub onEntering(ByVa l sender As Object, ...) Handles _
txt1.Enter,
txt2.Enter, txt3.Enter
CType(sender, TextBox).Select All()
End Sub
Is it possible to create a similar control array that I could stuff the
textboxes and the combobox into? If yes, how is this done? What kind of
control object could I use to hold different controls? And how do I check if
sender is a
Textbox or combobox?
If CType(sender, TextBox) = True Then...? is this doable?
If CType(sender, ComboBox) = True Then...?
Thanks,
Rich 4 1697
"Rich" <Ri**@discussio ns.microsoft.co m> wrote in message
news:6E******** *************** ***********@mic rosoft.com... Hello,
I have 3 textboxes and 1 combobox on a form. On entering the control I want to select all the text. I can make an array of textboxes like this:
Dim arrTxt As TextBox() = {txt1, txt2, txt3}
Then I loop through that array
Private Sub onEntering(ByVa l sender As Object, ...) Handles _ txt1.Enter, txt2.Enter, txt3.Enter CType(sender, TextBox).Select All() End Sub
Is it possible to create a similar control array that I could stuff the textboxes and the combobox into? If yes, how is this done? What kind of control object could I use to hold different controls?
Dim arr As Control() = {txt1, txt2, txt3}
or
Dim arr As Object() = {txt1, txt2, txt3}
And how do I check if sender is a Textbox or combobox?
If CType(sender, TextBox) = True Then...? is this doable? If CType(sender, ComboBox) = True Then...?
No, you would use:
If TypeOf sender Is TextBox Then
ElseIf TypeOf sender Is ComboBox Then
Also, make sure your event handler handles the lowest common denominator in
terms of EventArgs. All EventArgs inherit from System.EventArg s... so use
that.
arr_Click(ByVal sender As System.Object, ByVal e As System.EventArg s)
Handles ...
NOT
arr_Click(ByVal sender As System.Object, ByVal e As
SomeListViewSpe cialEventArgs) Handles ...
--
-C. Moya www.cmoya.com
Thanks very much for your reply. Your suggestion worked perfectly!
(for posterity here is what I did)
Dim arr As Control()
Private Sub Form1_Load(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
arr = New Control() {txt1, txt2, txt3, txt4, cbo1}
End Sub
Private Overloads Sub OnEnter(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles _
txt1.Enter, txt2.Enter, txt3.Enter,
txt4.Enter, cbo1.Enter
If TypeOf sender Is TextBox Then
MessageBox.Show ("Textbox " & CType(sender, TextBox).Name)
ElseIf TypeOf sender Is ComboBox Then
MessageBox.Show ("Combobox " & CType(sender, ComboBox).Name)
End If
End Sub
"CMM" wrote: "Rich" <Ri**@discussio ns.microsoft.co m> wrote in message news:6E******** *************** ***********@mic rosoft.com... Hello,
I have 3 textboxes and 1 combobox on a form. On entering the control I want to select all the text. I can make an array of textboxes like this:
Dim arrTxt As TextBox() = {txt1, txt2, txt3}
Then I loop through that array
Private Sub onEntering(ByVa l sender As Object, ...) Handles _ txt1.Enter, txt2.Enter, txt3.Enter CType(sender, TextBox).Select All() End Sub
Is it possible to create a similar control array that I could stuff the textboxes and the combobox into? If yes, how is this done? What kind of control object could I use to hold different controls?
Dim arr As Control() = {txt1, txt2, txt3} or Dim arr As Object() = {txt1, txt2, txt3}
And how do I check if sender is a Textbox or combobox?
If CType(sender, TextBox) = True Then...? is this doable? If CType(sender, ComboBox) = True Then...?
No, you would use:
If TypeOf sender Is TextBox Then ElseIf TypeOf sender Is ComboBox Then
Also, make sure your event handler handles the lowest common denominator in terms of EventArgs. All EventArgs inherit from System.EventArg s... so use that.
arr_Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ...
NOT
arr_Click(ByVal sender As System.Object, ByVal e As SomeListViewSpe cialEventArgs) Handles ...
-- -C. Moya www.cmoya.com
Why not fill the array in the declaration instead of waiting until
Form_Load?
Private arr As Control() = {txt1, txt2, txt3, txt4, cbo1}
Keep in mind that your form could be fully loaded and working, but Form_Load
isn't called until it is *shown* for the first time (this behavior is
different than VB.Classic). The chances of you (some method of yours or
event or whatever) of accessing arr before that happens is great. Like this:
Dim frm as New MyForm
frm.SetSomeProp ertiesOfControl s()
frm.Show()
Doh! Exception on SetSomeProperti es(). My "arr" wasn't initialized yet!!!
Also, "Private" not "Dim" is the common convention when declaring variables
at the class level.
--
-C. Moya www.cmoya.com
"Rich" <Ri**@discussio ns.microsoft.co m> wrote in message
news:01******** *************** ***********@mic rosoft.com... Thanks very much for your reply. Your suggestion worked perfectly! (for posterity here is what I did)
Dim arr As Control()
Private Sub Form1_Load(ByVa l sender As System.Object, _ ByVal e As System.EventArg s) Handles MyBase.Load arr = New Control() {txt1, txt2, txt3, txt4, cbo1} End Sub
Private Overloads Sub OnEnter(ByVal sender As System.Object, _ ByVal e As System.EventArg s) Handles _ txt1.Enter, txt2.Enter, txt3.Enter, txt4.Enter, cbo1.Enter If TypeOf sender Is TextBox Then MessageBox.Show ("Textbox " & CType(sender, TextBox).Name) ElseIf TypeOf sender Is ComboBox Then MessageBox.Show ("Combobox " & CType(sender, ComboBox).Name) End If End Sub
"CMM" wrote:
"Rich" <Ri**@discussio ns.microsoft.co m> wrote in message news:6E******** *************** ***********@mic rosoft.com... > Hello, > > I have 3 textboxes and 1 combobox on a form. On entering the control I > want > to select all the text. I can make an array of textboxes like this: > > Dim arrTxt As TextBox() = {txt1, txt2, txt3} > > Then I loop through that array > > Private Sub onEntering(ByVa l sender As Object, ...) Handles _ > txt1.Enter, > txt2.Enter, txt3.Enter > CType(sender, TextBox).Select All() > End Sub > > Is it possible to create a similar control array that I could stuff the > textboxes and the combobox into? If yes, how is this done? What kind > of > control object could I use to hold different controls?
Dim arr As Control() = {txt1, txt2, txt3} or Dim arr As Object() = {txt1, txt2, txt3}
> And how do I check if > sender is a > Textbox or combobox? > > If CType(sender, TextBox) = True Then...? is this doable? > If CType(sender, ComboBox) = True Then...?
No, you would use:
If TypeOf sender Is TextBox Then ElseIf TypeOf sender Is ComboBox Then
Also, make sure your event handler handles the lowest common denominator in terms of EventArgs. All EventArgs inherit from System.EventArg s... so use that.
arr_Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ...
NOT
arr_Click(ByVal sender As System.Object, ByVal e As SomeListViewSpe cialEventArgs) Handles ...
-- -C. Moya www.cmoya.com
Also the choice of name for your event handler, "OnEnter," is 100% BAD.
That's a sub of the base FORM class which is why I surmise you put
"Overloads" on (I take it the compiler complained and told you to put
"overloads" and you did it without really knowing what it meant). Why not
call your event handler something like
MyControls_Ente r(...) Handles txt1.Enter, txt2.Enter ...
--
-C. Moya www.cmoya.com
"Rich" <Ri**@discussio ns.microsoft.co m> wrote in message
news:01******** *************** ***********@mic rosoft.com... Thanks very much for your reply. Your suggestion worked perfectly! (for posterity here is what I did)
Dim arr As Control()
Private Sub Form1_Load(ByVa l sender As System.Object, _ ByVal e As System.EventArg s) Handles MyBase.Load arr = New Control() {txt1, txt2, txt3, txt4, cbo1} End Sub
Private Overloads Sub OnEnter(ByVal sender As System.Object, _ ByVal e As System.EventArg s) Handles _ txt1.Enter, txt2.Enter, txt3.Enter, txt4.Enter, cbo1.Enter If TypeOf sender Is TextBox Then MessageBox.Show ("Textbox " & CType(sender, TextBox).Name) ElseIf TypeOf sender Is ComboBox Then MessageBox.Show ("Combobox " & CType(sender, ComboBox).Name) End If End Sub
"CMM" wrote:
"Rich" <Ri**@discussio ns.microsoft.co m> wrote in message news:6E******** *************** ***********@mic rosoft.com... > Hello, > > I have 3 textboxes and 1 combobox on a form. On entering the control I > want > to select all the text. I can make an array of textboxes like this: > > Dim arrTxt As TextBox() = {txt1, txt2, txt3} > > Then I loop through that array > > Private Sub onEntering(ByVa l sender As Object, ...) Handles _ > txt1.Enter, > txt2.Enter, txt3.Enter > CType(sender, TextBox).Select All() > End Sub > > Is it possible to create a similar control array that I could stuff the > textboxes and the combobox into? If yes, how is this done? What kind > of > control object could I use to hold different controls?
Dim arr As Control() = {txt1, txt2, txt3} or Dim arr As Object() = {txt1, txt2, txt3}
> And how do I check if > sender is a > Textbox or combobox? > > If CType(sender, TextBox) = True Then...? is this doable? > If CType(sender, ComboBox) = True Then...?
No, you would use:
If TypeOf sender Is TextBox Then ElseIf TypeOf sender Is ComboBox Then
Also, make sure your event handler handles the lowest common denominator in terms of EventArgs. All EventArgs inherit from System.EventArg s... so use that.
arr_Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ...
NOT
arr_Click(ByVal sender As System.Object, ByVal e As SomeListViewSpe cialEventArgs) Handles ...
-- -C. Moya www.cmoya.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Christian H |
last post by:
I have just created a custom control. it consists of a radiobuttonlist, and
a validator for that radiobuttonlist. I've added a property in my control
that holds a placeholder. I want to use this placeholder, so that I can add
the validator of my control somewhere else in the page than "inside" my
custom control.
By design it would be like this:
<someplaceholder></someplaceholder>
<myControl></myControl>
|
by: wpy |
last post by:
Hi,
Does anybody know how to create multiple control with same ID or name in
asp.net and request the controls's value in array form? For example the vb
control can have same same but with different index.
Thanks.
|
by: michele |
last post by:
Hi, i'm trying to create some htmlinputfile controls at runtime in my page,
based on a integer variable (for example 5)
This is simple for the html code, but i don't know how to manage them in the
codebehind file, i've tryed to put them all in an array
protected HtmlInputFile filesUp = new HtmlInputFile;
but this doesn't work, so i can't get a reference to the controls in the
code...
Please help me
|
by: Daniel |
last post by:
Hi,
Does anyone know if it is possible to put an aspx page inside of another? OR
run an aspx page and capture the output as a string and then write this out
to a page....
So for example say you have a page that takes an id number as a query string
and displays different things based on that id number.
If you were able to loop through running the aspx pages with id=100, id=200,
|
by: rushikesh.joshi |
last post by:
Hi All,
I want some charting functionality in my ASP.NET application.
I want to show a multiple bar on my web page. It's based on down time
of different servers.
like
server1: down betn 4 AM to 5 AM and 6 PM to 7 PM
server2: down betn 7 AM to 7:30 AM
server3: down betn 3 AM to 5 AM and 2 Pm to 3 PM
| |
by: Matt |
last post by:
Hi all,
I'm trying to create a system where it reads a number of records from
a database and then creates a row in the GUI that contains a single
field from the database and a button that has a reference to the
record. This way, once the task has been accomplished, the button can
be pressed next to the field and a time-stamp is placed into the
database.
Can anyone point me in the direction of either a tutorial or
|
by: shapper |
last post by:
Hello,
I have been creating a few controls and I have a problem.
I want to create a control that renders a TextBox, a Label, and a few
more controls.
Is it possible to create such a control without all these controls to
be wrapped in a Tag?
|
by: lxyone |
last post by:
Using a flat file containing table names, fields, values whats the
best way of creating html pages?
I want control over the html pages ie
1. layout
2. what data to show
3. what controls to show - text boxes, input boxes, buttons,
hyperlinks ie the usual.
The data is not obtained directly from a database.
|
by: Arthur Milfait |
last post by:
hey there,
i'd like to do some wild thing like this:
imagine a simple page with a navigation menu and an iframe. clicking
on links in the menu loads the according page in the iframe. the menu
is a web-usercontrol of type "MenuList" that uses web-usercontrols of
type "MenuItem" for each link. so far nothing special. but now i'd
like each page that can be loaded to be of an interface/type
"IMenuItem" that publishes a getter for the...
|
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: 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,...
|
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: 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...
|
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: 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 we have to send another system
|
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...
| |