WPF ComboBox空值 [英] WPF ComboBox null value
问题描述
请查看此XAML:
Hi,
please have a look to this XAML:
<ComboBox Grid.Row="1" Grid.Column="3" Name="cmbNazionalitaProp" Width="230" Margin="0,5,20,2"
ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" SelectedValuePath = "codice"
DisplayMemberPath="descrizione" SelectedValue="{Binding Path=nazionalitam,Mode=TwoWay,UpdateSourceTrigger=LostFocus}"/>
以及我班上的属性定义:
and to the property definition in my class:
Private _nazionalitam As Nullable(Of Int32)
Public Property nazionalitam() As Nullable(Of Int32)
Get
Return _nazionalitam
End Get
Set(ByVal value As Nullable(Of Int32))
_nazionalitam = value
NotifyPropertyChange("nazionalitam")
End Set
End Property
我不知道为什么_nazionalitam返回值等于零,即使数据库字段中的值为NULL.
有人可以帮助我吗?
非常感谢您
盖伊
I don''t know why the _nazionalitam return value is equal to zero even if the value in the database field is NULL.
Anybody can help me?
Thank you very much
Gae
Public Function getAllNazionalita() As ObservableCollection(Of Nazionalita)
Dim lNazionalita As New ObservableCollection(Of Nazionalita)
Dim Nazionalita As Nazionalita
'lNazionalita.Add(Nothing)
Try
tempDataReader = SelectData("SELECT * FROM TGESI_NAZIONALITA WHERE COD_ENTE = '" & codEnte & "' ORDER BY CODICE")
If tempDataReader.HasRows Then
Do While tempDataReader.Read
Nazionalita = New Nazionalita(codEnte,
formattaValore(tempDataReader("CODICE")),
formattaValore(tempDataReader("DESCRIZIONE")),
formattaValore(tempDataReader("SIGLA")))
lNazionalita.Add(Nazionalita)
Loop
tempDataReader.Close()
End If
Catch ex As Exception
MsgBox("Errore nella lettura della lista delle Tratte" & vbCrLf & ex.Message)
tempDataReader.Close()
lNazionalita = Nothing
End Try
Return lNazionalita
End Function
并在Load事件中
Dim NazPropMot As ObservableCollection(Nazionalita)
NazPropMot = New ObservableCollection(Nazionalita)
NazPropMot = VeiManager.getAllNazionalita
cmbNazionalitaProp.ItemsSource = NazPropMot
谢谢
Gae
and in the Load event
Dim NazPropMot As ObservableCollection(Of Nazionalita)
NazPropMot = New ObservableCollection(Of Nazionalita)
NazPropMot = VeiManager.getAllNazionalita
cmbNazionalitaProp.ItemsSource = NazPropMot
Thank you
Gae
推荐答案
数据库中的Null值在vb.net中将为DBNull,而不是Null.您将需要检查该值是否为DBNull,如果为true则返回Null.我假设函数formattaValore尚未执行该操作,或者如果值是DBNull,则返回0.
祝你好运!
The Null value from the database will be DBNull in vb.net and not Null. You would need to check if the value is DBNull and return Null if that''s true. I''m assuming the function formattaValore does not do that yet or returns 0 if the value is DBNull.
Good luck!
这篇关于WPF ComboBox空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!