A
A
Alex45G2016-04-07 14:26:28
C++ / C#
Alex45G, 2016-04-07 14:26:28

C# wpf dataGrid comboBox - why is a type assigned when an option is selected and when data is entered, they are not written?

Hello!
I am new to c# wpf. I am writing my first application and asking for help.
I made a client application that accesses the database and displays its contents in a dataGrid for further editing.
796ca6d722d84d73b5624a87f1da3f02.PNG
At the same time, 2 problems arose:
1) When a status is selected (in a comboBox), in addition to the status itself, the cell also displays the type:
"System.Windows.Controls.ComboBoxItem: To work" instead of "To work".
Description of ComboBox: (it's in resources)

<DataTemplate x:Key="StatusTemplate" >
            <TextBlock Text="{Binding Path=status, ConverterParameter=DefaultToString}"/>
</DataTemplate>
<DataTemplate x:Key="EditingStatusTemplate">
            <ComboBox SelectedItem="{Binding Path=status, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" DropDownOpened="ComboBox_DropDownOpened">
                <ComboBoxItem Content="Черновик" IsEnabled="True"/>
                <ComboBoxItem Content="В работу" IsEnabled="True"/>
                <ComboBoxItem Content="В работе" IsEnabled="True"/>
                <ComboBoxItem Content="Остановлен" IsEnabled="True"/>
                <ComboBoxItem Content="Завершен" IsEnabled="True"/>
                <ComboBoxItem Content="Завершен по N2" IsEnabled="True"/>
            </ComboBox>
</DataTemplate>

in DataGrid.Columns
<DataGridTemplateColumn Header="Статус" CanUserResize="False" CellTemplate="{StaticResource StatusTemplate}" CellEditingTemplate="{StaticResource EditingStatusTemplate}"/>

2) when entering data into columns of type DataGridTextColumn and DataGridComboBoxColumn in dataGrid'e in the line in which the data was added, it is not displayed during debugging. And I want to check if all the cells in the row are filled and if so, then allow editing the status.
Column description example:
<DataGridTextColumn Binding="{Binding Path=progress}" ClipboardContentBinding="{x:Null}" Header="Прогресс" CanUserResize="False"/>

I tried to check the contents of the dataGrid in the handler using the debugger:
private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
            DataGrid dg = dataGrid;
}

And in the handler:
private void dataGrid_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)

I check whether all other cells are filled except for the status, and if so, I allow it to be edited.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question