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(ByVal sender As Object, ...) Handles _
txt1.Enter,
txt2.Enter, txt3.Enter
CType(sender, TextBox).SelectAll()
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 1669
"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.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(ByVal sender As Object, ...) Handles _ txt1.Enter, txt2.Enter, txt3.Enter CType(sender, TextBox).SelectAll() 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.EventArgs... so use
that.
arr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles ...
NOT
arr_Click(ByVal sender As System.Object, ByVal e As
SomeListViewSpecialEventArgs) 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(ByVal sender As System.Object, _
ByVal e As System.EventArgs) 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.EventArgs) 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**@discussions.microsoft.com> wrote in message news:6E**********************************@microsof t.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(ByVal sender As Object, ...) Handles _ txt1.Enter, txt2.Enter, txt3.Enter CType(sender, TextBox).SelectAll() 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.EventArgs... so use that.
arr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ...
NOT
arr_Click(ByVal sender As System.Object, ByVal e As SomeListViewSpecialEventArgs) 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.SetSomePropertiesOfControls()
frm.Show()
Doh! Exception on SetSomeProperties(). 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**@discussions.microsoft.com> wrote in message
news:01**********************************@microsof t.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(ByVal sender As System.Object, _ ByVal e As System.EventArgs) 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.EventArgs) 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**@discussions.microsoft.com> wrote in message news:6E**********************************@microsof t.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(ByVal sender As Object, ...) Handles _ > txt1.Enter, > txt2.Enter, txt3.Enter > CType(sender, TextBox).SelectAll() > 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.EventArgs... so use that.
arr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ...
NOT
arr_Click(ByVal sender As System.Object, ByVal e As SomeListViewSpecialEventArgs) 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_Enter(...) Handles txt1.Enter, txt2.Enter ...
--
-C. Moya www.cmoya.com
"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:01**********************************@microsof t.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(ByVal sender As System.Object, _ ByVal e As System.EventArgs) 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.EventArgs) 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**@discussions.microsoft.com> wrote in message news:6E**********************************@microsof t.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(ByVal sender As Object, ...) Handles _ > txt1.Enter, > txt2.Enter, txt3.Enter > CType(sender, TextBox).SelectAll() > 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.EventArgs... so use that.
arr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ...
NOT
arr_Click(ByVal sender As System.Object, ByVal e As SomeListViewSpecialEventArgs) 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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |