Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

This is an easy one guys i am sure - i just dont know how to do it...

 

I want to do this...

 

***THIS IS VB6 CODE!***

 

Dim ctrX As Control

 

For Each ctrX In Controls

 

If (TypeOf ctrX Is ComboBox) And (ctrX.Container Is objFrame) Then

 

ctrX.ListIndex = 0

 

End If

 

If (TypeOf ctrX Is ListBox) Then

 

For intLoopCounter = 1 To ctrX.ListCount Step 1

 

ctrX.Selected(intLoopCounter - 1) = False

 

Next intLoopCounter

 

End If

 

Next ctrX

 

 

When i have upgraded my code to .Net it has decided that this will not longer work.

 

This is the code that i am not given:

 

Dim ctrX As System.Windows.Forms.Control

Dim objFrame As Object

 

For Each ctrX In Controls

'UPGRADE_WARNING: TypeOf has a new behavior. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1041"'

 

If (TypeOf ctrX Is System.Windows.Forms.TextBox) And (ctrX.Parent Is objFrame) Then

ctrX.Text = ""

End If

 

'UPGRADE_WARNING: TypeOf has a new behavior. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1041"'

 

If (TypeOf ctrX Is System.Windows.Forms.ComboBox) And (ctrX.Parent Is objFrame) Then

 

'UPGRADE_WARNING: Couldn't resolve default property of object ctrX.ListIndex. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1037"'

 

ctrX.ListIndex = 0

 

End If

 

'UPGRADE_WARNING: TypeOf has a new behavior. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1041"'

 

If (TypeOf ctrX Is System.Windows.Forms.ListBox) Then

 

'UPGRADE_WARNING: Couldn't resolve default property of object ctrX.ListCount. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1037"'

 

For intLoopCounter = 1 To ctrX.ListCount Step 1

 

'UPGRADE_WARNING: Couldn't resolve default property of object ctrX.Selected. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1037"'

 

ctrX.Selected(intLoopCounter - 1) = False

 

Next intLoopCounter

 

End If

 

Next ctrX

 

This has flumuxed me - simple to fix? I have no idea, i thought it would be but after some searching it appears no.

 

The errors i have in the task area window of the vb.net screen

 

 

'GetCheckedIndices' is not a member of 'System.Windows.Forms.CheckedListBox'.

'ListCount' is not a member of 'System.Windows.Forms.Control'.

'ListIndex' is not a member of 'System.Windows.Forms.Control'.

'Selected' is not a member of 'System.Windows.Forms.Control'.

 

Please help,

 

Papa.

without time nothing ever ends
  • *Gurus*
Posted

You have to recursively go through all the controls on your form like so:

 

Dim c As Control

For Each c In Parent.Controls
   'Recurse passing c, first call passes Form itself
   If TypeOf c Is ListBox Then DirectCast(c, ListBox).SelectedIndex = -1
   If TypeOf c Is TextBox Then c.Text = ""
Next c

 

Untested of course but I'm sure you get my drift.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • Leaders
Posted

i might try that way to see how it works , i created another way which does work :

  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       Dim f As Control
       For Each f In Form1.ActiveForm.Controls '// form's name
           If TypeOf f Is ComboBox Then
               clearBox(f)
           ElseIf TypeOf f Is ListView Then
               ClearListView(f)
           End If
       Next
   End Sub
   Public Sub clearBox(ByVal cb As ComboBox)
       cb.Items.Clear()
   End Sub
   Public Sub ClearListView(ByVal lv As ListView)
       lv.Items.Clear()
   End Sub

  • 3 weeks later...
Posted

In ASP.Net

 

Dim c As Control

For Each c In Parent.Controls
   'Recurse passing c, first call passes Form itself
   If TypeOf c Is ListBox Then DirectCast(c, ListBox).SelectedIndex = -1
   If TypeOf c Is TextBox Then c.Text = ""
Next c

Doesn't work. There isn't a .text item for c

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...