本文介绍了WPF ComboBox空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


请查看此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

推荐答案


这篇关于WPF ComboBox空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 22:50