|
Hi,
How can I make Control Array in VB.net.
Like
TextBox1(0)
TextBox1(1)
TextBox1(2)
TextBox1(3)
TextBox1(4)
Thanks !
|
|
|
|
|
You don't. Control arrays are a thing of the past.
You can mimic them by using the Handles caluse of the event signature though. Thsi allows multiple controls to send thier events all to a common event handler.
Private Sub Button1_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs)_
Handles Button1.Click, Button2.Click, Button3.Click
Select Case DirectCast(sender, Button).Name
Case "Button1"
MessageBox.Show("Button1!")
Case "Button2"
MessageBox.Show("Button2!")
Case "Button3"
MessageBox.Show("Button3!")
Case Else
End Select
End Sub
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
My Blog[^]
|
|
|
|
|
'I have an example that can help you.
'Sorry, my english is bad !
'This is the file "Form1.vb"
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(24, 320)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(80, 24)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(400, 357)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
' MsgBox("OK")
' Dim V(0) As Windows.Forms.Button
'With V(0)
'.Size = New System.Drawing.Size(152, 24)
'.Location = New System.Drawing.Point(64, 216)
'End With
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Dim tb(2) As TextBox
For n As Integer = 0 To 2
''Crea le caselle ditesto richieste
tb(n) = New TextBox
tb(n).Size = New System.Drawing.Size(400, 30)
tb(n).Location = New System.Drawing.Point(59, 40 + n * 40)
''Questo identifica il controllo TextBox
tb(n).Name = CStr(n + 1)
tb(n).Tag = CStr(n + 1)
tb(n).Text = CStr(n + 1)
''Viene aggiunto il controllo alla lista controlli
Me.Controls.Add(tb(n))
''Crea i gestori d''evento
'AddHandler tb.KeyPress, AddressOf TextBox_KeyPress
AddHandler tb(n).TextChanged, AddressOf TextBox_TextChanged
'AddHandler tb.MouseEnter, AddressOf TextBox_MouseEnter
'AddHandler tb.MouseLeave, AddressOf TextBox_MouseLeave
Next
End Sub
Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim s As String
s = sender.tag
CiSono(s)
End Sub
End Class
'This is the file "Module1.vb"
Module Module1
Public tb(2) As TextBox
Public Sub CiSono(ByRef s As String)
MsgBox(s)
End Sub
End Module
|
|
|
|
|
hello!
any know how to color the items of a combobox?
thanks
wilson
|
|
|
|
|
You have to handle the DrawItem event of the ComboBox:
DrawItemEventArgs[^]
The example is for a ListBox, but the theory is exactly the same.
Hope this helps
Tom
|
|
|
|
|
thanks tom.
i'm beginner in vb.net and in the sample i don't understant where put the code...
please help me.
thanks
wilson
|
|
|
|
|
Hi all,
Can anybody let me know how to change the column name of datagrid.
It displays the same name as per in table.
I want to change it.
let Emp_Code is the column name in table and I want the column name as Employee Code to be displayed.
Please help.
Suman Singh
|
|
|
|
|
It is possible through SQL query. Use 'ALias' command of sql.
example
select 'FirstName'=au_fname,'LastName'=au_lname from authors
use this query, hope you understand it.
au_fname and au_lname are column names, where as 'First Name' and 'Last Name' are fake names.
bye
EsHbAn BaHaDuR
|
|
|
|
|
I attach a text box on form. user has to enter date in that text box. How can i set the format mask for date like dd:mm:yyyy
EsHbAn BaHaDuR
|
|
|
|
|
The standard TextBox control doesn't support masked editing. You have to use the old ActiveX MaskedEdit control for this. A reference for which you can find here[^] on MSDN.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Here's instruction for including the control in your project: [^]
Are you familiar with the MaskedEdit control in VB6? It's just about the same. If you aren't familiar, then you can Google it or look further on vbcity.com, just remember you are looking for VB6 instructions, not VB.NET.
|
|
|
|
|
I want to select some data from database and display it in DATAGRID control, how can i use it without using "Data Adapter" and "DataSET" objects
EsHbAn BaHaDuR
|
|
|
|
|
I don't think you can do it without the two, if you are using database.
Please wait for another reply.
|
|
|
|
|
How else are you going to get the data out of the database?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am a new learner of VB.net.
Can anybody let me know, how to call a buton_click procedure on textbox.keypress event.
Suman Singh
suman9730@hotmail.com
|
|
|
|
|
place the following line of code into your keypress event handler:
me.myButton.PerformClick()
-jim
|
|
|
|
|
Hi,
Thanks for your quick reply.
But how can I identify the button if i have 5 buttons on the form.
Please help again.
A learner this side.
Thanks!
|
|
|
|
|
is it a situation where you want to perform a click on a particular button based on which text box has the focus?
if this is the case, just evaluate what you want to determine and perform a click on the appropriate button. for instance
Private Sub myKeyPressHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles myTextBox.KeyPress,
someOtherTextBox.KeyPress,
yetAnotherTextBox.KeyPress
If (Object.ReferenceEquals(sender, Me.myTextBox)) Then
me.myButton.PerformClick()
elsif (object.ReferenceEquals(sender, me.someOtherTextBox))
me.someOtherButton.PerformClick()
elseif (object.ReferenceEquals(sender, me.yetAnotherButton))
me.yetAnotherButton.PerformClick()
else
messagebox.show("It was yet even another textbox that received the text!")
End If
End Sub hope this helps you out.
-jim
|
|
|
|
|
Thanks again Jim,
I want to press Enter key in textbox after giving my password (let say)
And by pressing Enter key, the code written in
Private sub Login_Validate_button(by val sender as object......)handles....
----
----
----
End Sub
get invoked.
How can I call this button procedure by pressing the Enter key in textbox.
Thanks !
|
|
|
|
|
no problem Suman,
in this case, just handle the keypress as follows...
private sub txtPassword_KeyPress(byval sender as object, byval e as System.windows.forms.keyeventargs) handles txtPassword.KeyPress
if (e.keycode=keys.enter) then
me.btnLogin.PerformClick()
end if
End Sub when working with event handlers, always look to the event arguments for context specific data regarding the event being raised.
-jim
|
|
|
|
|
i need to loop some rows in my datagrid to add them and show the total.
i am using:
<br />
Dim dr As DataRow<br />
Dim Amount As Double = 0<br />
For Each dr As System.Data.DataRow _<br />
In ds.Tables(0)<br />
dr = dr + ds.Tables(0).Rows.Item("Amount")<br />
Next<br />
Me.Text = ("My Balance $") & Amount.ToString<br />
everything is fine except the underlined part. it keeps saying that it is a member of system.data.datatable which is not a collection type. does anyone know what i am doing wrong?
Makniteasy
|
|
|
|
|
Tables(0) is not a collection, it's a specific table.
...
For each r as Datarow in ds.Tables(0).Rows
... by the way your initial declaration of dr is reduntant since you are initializing it again within your for statement. just thought i'd mention it.
-jim
|
|
|
|
|
thanks that fixed that problem but now i have another:
<br />
Dim Amount As Double = 0<br />
<br />
For Each dr As DataRow In ds.Tables(0).Rows<br />
<br />
dr = dr + ds.Tables(0).item("Amount")<br />
<br />
Next<br />
Me.Text = ("My Balance $") & ("Amount").ToString<br />
now this is underlined. i think im lost in the loop now.any more suggestions?
Makniteasy
|
|
|
|
|
can you give us an idea of exactly what it is you're trying to do? the code you've provided doesn't really make much sense.
just a brief description should help.
-jim
|
|
|
|
|
You're not adding the amounts. You're actually trying to add a Column to a DataRow.
I think you're looking for:
Dim Amount As Double = 0
For Each dr As DataRow In ds.Tables(0).Rows
Amount += dr.Item("Amount")
Next
Me.Text = "My Balance $" & Amount.ToString()
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|