none
how to set default text for DataGridComboBoxColumn

    Question

  • Hai

    I want to set default text for DataGridComboBoxColumn on entering the cell. For this I use this code

    Enm_PR is an Enum.

    <DataGridComboBoxColumn ItemsSource="{Binding Source={StaticResource Enm_PR}}" SelectedItemBinding ="{Binding M_Purch_Ret,UpdateSourceTrigger=LostFocus}" SelectedValuePath="{Binding M_Purch_Ret}" Width="80" Header="Purch/Return">
                        <DataGridComboBoxColumn.ElementStyle>
                            <Style TargetType="ComboBox">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=SelectedItemId}" Value="{x:Static sys:String.Empty}">
                                        <Setter Property ="Text" Value ="Purchase"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </DataGridComboBoxColumn.ElementStyle>
                    </DataGridComboBoxColumn>
    

    Here "Purchase" is an item from combo

    Problem is data grid combo column text not setting  to text "Purchase". 

    please help me.

    thanks


    programmer

    Thursday, December 07, 2017 3:24 PM

All replies

  • Hi,

    You bind the DataGridComboBoxColumn ItemsSource with a collection,

    You should bind the SelectedValueBinding with a item which is in collection.

    SelectedValuePath should bind one property of the item .Such as;

    <DataGridComboBoxColumn Header="Current Student"
    
        SelectedValueBinding="{Binding Path=CurrentStudent}"
    
        SelectedValuePath="StudentID"
    
        DisplayMemberPath="StudentName"
    
        ItemsSource="{Binding Path=StudentCollection}">
    
    <DataGridComboBoxColumn>
    CurrentStudent = StudentCollection[1];


    Sincerely,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 08, 2017 3:07 AM
    Moderator