Hallo Zusammen,
mit folgendem Code laufe ich durch eine Sammlung von Controlls die ich zu Laufzeit in einem Panel plaziert habe:
Public Sub readProjectUserField(ByVal Controls As Control.ControlCollection)
Dim result As Object
For Each control As Control In Controls
If (TypeOf control Is TextBox) Then
result = myUserFieldDefinition.read(CType(control, _
TextBox).Name.Replace("Value_ID", "").Replace("X", ""), _
currentProject_ID).ToString
If result = "-2" Or result = "-3" Then
CType(control, TextBox).Text = ""
Else
CType(control, TextBox).Text = result
End If
End If
If (TypeOf control Is ComboBox) Then
Dim myComboBox As ComboBox = CType(control, ComboBox)
result = myUserFieldDefinition.read(CType(control, _
ComboBox).Name.Replace("Value_ID", "").Replace("X", ""), _
currentProject_ID)
If result < 0 Then
myComboBox.SelectedValue = -1
myComboBox.SelectedValue = -1
Else
myComboBox.SelectedValue = CInt(result)
myComboBox.SelectedValue = CInt(result)
End If
End If
If (TypeOf control Is CheckBox) Then
result = myUserFieldDefinition.read(CType(control, _
CheckBox).Name.Replace("Value_ID", "").Replace("X", ""), _
currentProject_ID)
If IsDBNull(result) = True Then result = 0
If result > 0 Then
CType(control, CheckBox).Checked = True
Else
CType(control, CheckBox).Checked = False
End If
End If
If (TypeOf control Is DateTimePicker) Then
Dim myDate As Date
myDate = DateAdd(DateInterval.Second, CDbl( _
myUserFieldDefinition.read(CType(control, _
DateTimePicker).Name.Replace("Value_ID", ""), _
currentProject_ID)), #1/1/1970#)
CType(control, DateTimePicker).Value = myDate
End If
If (control.Controls.Count > 0) Then
readProjectUserField(control.Controls)
End If
Next
End Sub Anhand des Namens des Controlls weis ich woher ich meine Daten holen muss.
Die weise ich meinen Controlls jetzt zu.
Das klappt für Text, Checkbox und Datetimepicker wunderbar.
Nur bei den ComboBoxen nicht.
Ich setzte schon den Wert zweimal (in der Hoffnung doppelt ist besser ;) )
Aber erst wenn ich die Daten aktualisiere bekomme ich die richtigen Werte.
Zum aktualisieren wird aber die gleich Sub oben aufgerufen?!?!?!
Ich habe auf
myComboBox.SelectedValue = CInt(result) mal einen Brackpoint gesetzt und schaue dann was myComboBox.SelectedValue für einen Wert hat.
Der steht danach auf Nothing!
Hat einer eine Idee was ich da falsch mache?
Gruß
Carsten |