Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Grid is already filled with data but when i change the mark and press submit direct it take the old value
if i pressed enter and the pressed submit it take the new value
I need to take the new value if i pressed submit direct
please find below all code used

Datagrid:

<DataGrid x:Name="GrdExamCheck" AutoGenerateColumns="False" HorizontalAlignment="Left" Background="{x:Null}" VerticalAlignment="Stretch" Canvas.Top="10" FontFamily="Times New Roman" Width="997" FontWeight="Bold" Canvas.Left="10"   >
                <DataGrid.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Setter Property="TextBlock.TextAlignment" Value="Center"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type DataGridCell}">
                                    <Grid Background="{TemplateBinding Background}">
                                        <ContentPresenter VerticalAlignment="Bottom"/>
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </DataGrid.CellStyle>
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Student ID" Visibility="Hidden" Binding="{Binding StuId}"/>
                    <DataGridTemplateColumn Header="Student" Width="180" IsReadOnly="True">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{Binding StuImage}" Width="50" Height="50" />
                                    <TextBlock Text="{Binding StuName}" VerticalAlignment="Bottom" FontFamily="Times New Roman" FontWeight="Bold" FontSize="13"/>
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTextColumn Header="Mark" Width="100" Binding="{Binding CheckMark}"></DataGridTextColumn>
                    <DataGridTemplateColumn Header="Factor" Width="100" IsReadOnly="True">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Factor}" TextAlignment="Center"  VerticalAlignment="Bottom" FontFamily="Times New Roman" FontWeight="Bold" FontSize="13"/>
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Header="Versions" Width="100" IsReadOnly="True">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding CheckUpdated}" VerticalAlignment="Bottom" TextAlignment="Center"  FontFamily="Times New Roman" FontWeight="Bold" FontSize="13"/>
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Header="Remark" Width="200" >
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Text="{Binding Remark}" VerticalAlignment="Bottom"  HorizontalAlignment="Stretch" FontFamily="Times New Roman" FontWeight="Bold" FontSize="13" Foreground="Black" BorderBrush="{x:Null}" Background="{x:Null}"/>
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Header="Absent" Width="70">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Button x:Name="BtnAbsent" Content=""  Width="40" Height="40" BorderBrush="{x:Null}" Click="BtnAbsent_Click" >
                                    <Button.Background>
                                        <ImageBrush ImageSource="/School Manager v001;component/Pics/absent.ico" Stretch="Uniform"/>
                                    </Button.Background>
                                </Button>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Header="Submit" Width="70">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Button x:Name="BtnSubmit" Content=""  Width="40" Height="40" BorderBrush="{x:Null}" Click="BtnSubmit_Click" >
                                    <Button.Background>
                                        <ImageBrush ImageSource="/School Manager v001;component/Pics/submitMark.ico" Stretch="Uniform"/>
                                    </Button.Background>
                                </Button>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Header="Attach" Width="70">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Button x:Name="BtnAttach" Content=""  Width="40" Height="40" BorderBrush="{x:Null}" Click="BtnAttach_Click" >
                                    <Button.Background>
                                        <ImageBrush ImageSource="/School Manager v001;component/Pics/attachment.ico" Stretch="Uniform"/>
                                    </Button.Background>
                                </Button>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>
XML





Submit click code :

var mark = GrdExamCheck.CurrentItem as Mark;
            if (mark != null)
            {
                InsertMark(int.Parse(LbExamIdContent.Content.ToString()), mark.StuId, DateTime.Now.ToShortDateString(), mark.Remark, Convert.ToDecimal(mark.CheckMark), Convert.ToDecimal(LbFactorContent.Content.ToString()));
            }
            FillClassStudentList(int.Parse(LbCLassIdContent.Content.ToString()));
C#




Mark Class for binding:

public class Mark
   {
       public int CheckId { set; get; }
       public int StuId { set; get; }
       public string StuName { set; get; }
       public string Date { set; get; }
       public int ExamId { set; get; }
       public string CheckMark { set; get; }
       public decimal Factor { set; get; }
       public string Remark { set; get; }
       public int StuPicid { set; get; }
       public BitmapImage StuImage { set; get; }
       public string CheckUpdated { get; set; }
   }
C#



Please guys help

What I have tried:

i tried the code of click and tried to refresh the Grid item
also i tried to get currentitem
but it did not work
Posted
Updated 30-Mar-19 23:02pm

This requires you to "trace" all the events that are "generated" in either case (tab click versus no tab and click), understand them, and then add the appropriate "fix".

No one is going to help you unless they have gone through exactly the same scenario (highly unlikely). You have no choice but to do more reading / testing and to educate yourself. Here's a related post that conveys the type of information you need to become familiar with if you plan on getting anywhere (re: data grids and editing).

WPF DataGrid CellEditEnding - DataSet Not Updating Till Row Lost Focus - Stack Overflow[^]
 
Share this answer
 
Binding="{Binding CheckMark,UpdateSourceTrigger=PropertyChanged}"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900