papa_k Posted June 12, 2003 Posted June 12, 2003 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. Quote without time nothing ever ends
*Gurus* divil Posted June 12, 2003 *Gurus* Posted June 12, 2003 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. Quote 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 dynamic_sysop Posted June 12, 2003 Leaders Posted June 12, 2003 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 Quote
ThePentiumGuy Posted June 12, 2003 Posted June 12, 2003 i dunno if this will help but how about something like this: if not textbox.text = nothing then textox.text = " " end if Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
TheWizardofInt Posted June 30, 2003 Posted June 30, 2003 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 Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.