Newbie

R

Robert

Used VB 6

Trying out VB.Net 2008

How is the following code made easier in .Net?

VB 6 sample.
'10 textboxes on a form.
Private Sub txtTest_GotFocus(Index as Integer)
txtTest(Index).SelStart=0
txtTest(Index).SelLength=Len(txtTest(Index).Text)

Exit Sub
End Sub

With VB.Net I am required to enter this in 10 seperate text box fields.
How is this easier???

Next Question.
How do you retrireve the ItemData from a combobox in VB.Net when it is not
there??

What is the limit of controls on a VB.Net form, since there is not longer
the Index of a control??

Any tips might help with the evaluation of .Net.
 
T

Teemu

Robert said:
Used VB 6

Trying out VB.Net 2008

How is the following code made easier in .Net?

VB 6 sample.
'10 textboxes on a form.
Private Sub txtTest_GotFocus(Index as Integer)
txtTest(Index).SelStart=0
txtTest(Index).SelLength=Len(txtTest(Index).Text)

Exit Sub
End Sub

With VB.Net I am required to enter this in 10 seperate text box fields.
How is this easier???

You can paste code like this that selects all the text. As you can see, you
can define many textboxes to work with single event.

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus,
TextBox3.GotFocus, TextBox4.GotFocus
DirectCast(sender, TextBox).SelectAll()
End Sub

Next Question.
How do you retrireve the ItemData from a combobox in VB.Net when it is not
there??

I think ComboBox's Text property is what you are looking for.
What is the limit of controls on a VB.Net form, since there is not longer
the Index of a control??

I haven't heard about any limitations but I'm quite sure that you can't
reach that level in normal use if there is a limit.

-Teemu
 
J

Jack Jackson

Used VB 6

Trying out VB.Net 2008

How is the following code made easier in .Net?

VB 6 sample.
'10 textboxes on a form.
Private Sub txtTest_GotFocus(Index as Integer)
txtTest(Index).SelStart=0
txtTest(Index).SelLength=Len(txtTest(Index).Text)

Exit Sub
End Sub

With VB.Net I am required to enter this in 10 seperate text box fields.
How is this easier???

Next Question.
How do you retrireve the ItemData from a combobox in VB.Net when it is not
there??

What is the limit of controls on a VB.Net form, since there is not longer
the Index of a control??

Any tips might help with the evaluation of .Net.
 
F

Family Tree Mike

Robert said:
Used VB 6

Trying out VB.Net 2008

How is the following code made easier in .Net?

VB 6 sample.
'10 textboxes on a form.
Private Sub txtTest_GotFocus(Index as Integer)
txtTest(Index).SelStart=0
txtTest(Index).SelLength=Len(txtTest(Index).Text)

Exit Sub
End Sub

With VB.Net I am required to enter this in 10 seperate text box fields.
How is this easier???

Next Question.
How do you retrireve the ItemData from a combobox in VB.Net when it is not
there??

What is the limit of controls on a VB.Net form, since there is not longer
the Index of a control??

Any tips might help with the evaluation of .Net.
--
Thanks in advance
Have a Great Day
bob
(e-mail address removed)


In your constructor do the following:

AddHandler TextBox1.GotFocus, AddressOf foo
AddHandler TextBox2.GotFocus, AddressOf foo
' etc... for each text box

Then add your handling function declared as such:

Public Sub foo(ByVal sender As Object, ByVal args As EventArgs)
Dim tb As TextBox = CType(sender, TextBox)
' do something with tb
End Sub
 
J

Jack Jackson

Used VB 6

Trying out VB.Net 2008

How is the following code made easier in .Net?

..Net is different. Some things are easier than in VB6, other things
are not.
VB 6 sample.
'10 textboxes on a form.
Private Sub txtTest_GotFocus(Index as Integer)
txtTest(Index).SelStart=0
txtTest(Index).SelLength=Len(txtTest(Index).Text)

Exit Sub
End Sub

If this procedure is an event handler for the GotFocus event for 10
textboxes (in .NET the documentation suggests using Enter instead of
GotFocus):

Private Sub txtbox_Enter(sender As Object, e As EventArgs) Handles
txt1.Enter, txt2.Enter, ...
DirectCast(sender, Textbox).SelectAll()
or
Dim txtbox As Textbox = DirectCast(sender, Textbox)

txtbox.SelectionStart = 0
txtbox.SelectionLength = txtbox.Text.Length
End Sub
With VB.Net I am required to enter this in 10 seperate text box fields.
How is this easier???

Next Question.
How do you retrireve the ItemData from a combobox in VB.Net when it is not
there??

I'm not sure what you mean by "not there". A ComboBox has
SelectedIndex, SelectedItem and SelectedValue properties to indicate
which item is selected.
What is the limit of controls on a VB.Net form, since there is not longer
the Index of a control??

There is no practical limit that I am aware of for the number of
controls in a form or other container.
 
L

Lloyd Sheen

Teemu said:
Sorry about this. I haven't used VB6 lately and I didn't remember ItemData
correctly. In .NET there is no direct way to accomplish this feature.

Here is something about how to create an alternative way to use ItemData
in .NET:
http://www.mgbrown.com/PermaLink37.aspx

-Teemu


What you want to do is create collection of objects which you can then bind
to the combobox. When you have done this the selected item in the combobox
will be the object.

Example: (air code)

dim xx as list(of MyObject)
dim o1 as new MyObject with {. do inits}
xx.add (o1)

etc.
myComboBox.DataDisplay="the property to display"
myComboBox.datasource=xx

Now on a selectionchange event you can get an MyObject as:

dim mo as MyObject = ctype(myComboBox.selecteditem,MyObject)

Hope this helps
LS
 
T

Tom Shelton

Used VB 6

Trying out VB.Net 2008

How is the following code made easier in .Net?

VB 6 sample.
'10 textboxes on a form.
Private Sub txtTest_GotFocus(Index as Integer)
txtTest(Index).SelStart=0
txtTest(Index).SelLength=Len(txtTest(Index).Text)

Exit Sub
End Sub

With VB.Net I am required to enter this in 10 seperate text box fields.
How is this easier???

On the face of it it may look that way, but it's really not that way. I would
do something like this in my code (warning: air code!):

Public Class Form1
Inherits System.Windows.Forms.Form
Private txtBoxes() As TextBox

Public Sub New()
InitializeComponent()

txtBoxes = new TextBox() { _
TextBox1, _
TextBox2, _
TextBox3, _
TextBox4}

For Each txt As TextBox In txtBoxes
AddHandler txt.GotFocus, CommonFocusHandler
Next
End Sub

Private Sub CommonFocusHandler (ByVal sender As Object, ByVal e As EventArgs)
Dim txt As TextBox = TryCast (sender, TextBox)
If txt IsNot Nothing Then
' do stuff to text box
End If
End Sub
End Class

I know... Not exactly easier :) Not everything in .NET is. But, you can
still accomplish what you want in this case - it just takes a bit more setup :)
Next Question.
How do you retrireve the ItemData from a combobox in VB.Net when it is not
there??

You don't need it in .NET. Combobox and ListBox will store any arbitrary
object. You aren't limited to strings... There are couple of behaviors that
you should be aware of though when using this feature - the first, is that by
default the combobox will display the results of .ToString of the object.
Usually, the default .ToString simply prints out the type name - not very
usefull :) So, the way to overcome this is to:

1) Override the objects .ToString method to return something more appropriate
2) Change the ComboBox/ListBox DisplayProperty value to the name of the
property you want to use...

So, for a simple example (again, air code):

Public Class Person

Private _firstName As String
Private _lastName As String

Public Sub New()
End Sub

Public Sub New (ByVal firstName As String, ByVal lastName As String)
_firstName = firstName
_lastName = lastName
End Sub

Public Property FirstName() As String
Get
Return _firstName
End Get
Set (ByVal value As String)
_firstName = value
End Set
End Property

Public Property LastName() As String
Get
Return _lastName
End Get
Set (ByVal value As String)
_lastName = value
End Set
End Sub

Public ReadOnly Property FullName As String
Get
Retrun _lastName & ", " & _firstName
End Get
End Property

Public Override Function ToString() As String
Return FullName
End Function
End Class

Now you can create an array of these thingies like this:

Dim people() As Person = new Person() { _
New Person("John", "Smith"), _
New Person("Jerry", "Baker"), _
New Person("Sammy", "Simpleton")}

And then add them to a combobox:

ComboBox1.Items.AddRange (people)

Then, when an item is selected:

Private Sub combobox1_SelectedIndexChanged (ByVal sender As Object, ByVal e As EventArgs)
Person selectedPerson = TryCast (combobox1.SelectedItem, Person)
If selectedPerson IsNot Nothing Then
MessageBox.Show selectedPerson.FullName
End If
End Sub

What all of this amounts to - is that the combobox/listbox etc in .NET are far
more powerfull - and ItemData is a thing of the past. You can store a lot of additional data beyond a simple Long
value :) Oh, the days when I used to use those ItemData fields as a pointers
to additional data :)
What is the limit of controls on a VB.Net form, since there is not longer
the Index of a control??

Only memory and the number of windowhandles - which I believe is something
like 10,000 per process on an NT based system...
Any tips might help with the evaluation of .Net.

Yeah, forget VB6 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top