Assegnazioni a cascata in codice vb.net

mercoledì 11 febbraio 2009 - 10.38

maui.80 Profilo | Junior Member

Ciao a tutti....nuovo quesito (magari banale ma da cui ignoro la soluzione):

in codice vb.net voglio inserire delle azioni da fare uguali per 48 dropdownlist

es.
DropDownList1.Enabled = False
DropDownList2.Enabled = False
DropDownList3.Enabled = False
DropDownList4.Enabled = False
DropDownList5.Enabled = False
DropDownList6.Enabled = False
DropDownList7.Enabled = False
DropDownList8.Enabled = False
....fino a 48

facendo un ciclo da 1 a 48 come posso mettere la sintassi giusta per inserire il numero del contatore alla fine della dicitura DropDownList???

es. di quello che vorrei

do while i<49
DropDownlist(i).enable=False
i=i+1
end do

grazie dell'aiuto
MAURO

balfaz Profilo | Expert

puoi usare questo codice cosi al volo dovrebbe servire per il tuo quesito
Dim Controllo As Control
For Each Controllo In Me.Controls
If TypeOf Controllo Is DropDownList Then
Controllo.enabled = false
End If
Next

facci sapere

"Che in questo 2009 i nostri codici possano sconvolgere il mondo."

luigidibiasi Profilo | Guru

>>> balfaz ... scusa non avevo visto la risposta
Ciao,

l'esempio è fatto con i button ma credo funzioni con qualsiasi altro controllo

sul form che ho usato ci sono 4 button
button1 2 3 e 4

Dim k As Integer For k = 1 To 4 Dim p As String = "Button" & k Me.Controls(p).Enabled = False Next


Luigi Di Biasi
http://blogs.dotnethell.it/luigidibiasi/

maui.80 Profilo | Junior Member

funziona!!! grazie

step successivo:

se a tutti i DropDownList voglio far fare la medesima cosa tipo assegnazione valori:

es.
DropDownList1.Items(X).Value = dr("IDPROG")
DropDownList2.Items(X).Value = dr("IDPROG")
DropDownList3.Items(X).Value = dr("IDPROG")
DropDownList4.Items(X).Value = dr("IDPROG")
DropDownList5.Items(X).Value = dr("IDPROG")
DropDownList6.Items(X).Value = dr("IDPROG")
DropDownList7.Items(X).Value = dr("IDPROG")


ho provato ma non funziona...hai qualche dritta anche per questo caso?

luigidibiasi Profilo | Guru

Ciao,

>funziona!!! grazie
>
quale due due metodi usi? in base al metodo usi un codice diverso...

>step successivo:
>
>se a tutti i DropDownList voglio far fare la medesima cosa tipo
>assegnazione valori:
>
>es.
> DropDownList1.Items(X).Value = dr("IDPROG")
> DropDownList2.Items(X).Value = dr("IDPROG")
> DropDownList3.Items(X).Value = dr("IDPROG")
> DropDownList4.Items(X).Value = dr("IDPROG")
> DropDownList5.Items(X).Value = dr("IDPROG")
> DropDownList6.Items(X).Value = dr("IDPROG")
> DropDownList7.Items(X).Value = dr("IDPROG")
>
>

senza provare su vb ti scrivo questo codice poi sta a te cambiarlo...

dim obj as DropDownList
Dim k As Integer
For k = 1 To 4
Dim p As String = " DropDownList" & k
obj = Me.Controls(p)
obj.items(x).value=dr("IDPRO")
Next



Luigi Di Biasi
http://blogs.dotnethell.it/luigidibiasi/

balfaz Profilo | Expert

qui non capito cosa vuoi fare?

Luigi....figurati...no ti preoccupare


"Che in questo 2009 i nostri codici possano sconvolgere il mondo."

maui.80 Profilo | Junior Member

BINGOOOO

GRAZIE MILLE

CIAO MAURO
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5