Click here to Skip to main content
16,016,759 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I would like to make it so that when you double-click on a cell, the program defines an instance of the class and changes its attribute in the database, after which a request is sent to the server every 5 seconds, and the selected object will go to another table and disappear from the original one.

Essence EF:
C#
public class PushTable
    {
        public long id { get; set; }
        public string sn { get; set; }
        public string obis { get; set; }
        public string date { get; set; }
        public long evcode { get; set; }
        public int ReadBool { get; set; }
 
        public PushTable()
        {
            ReadBool = 0; // this row in the database should change to "1", after double clicking on the cell
        }
    }


Datagrid XAML:
XML
<DataGrid x:Name="tableNoRead"
                          AutoGenerateColumns="False"
                          Width="Auto"
                          ScrollViewer.CanContentScroll="True" 
                          ScrollViewer.VerticalScrollBarVisibility="Auto"
                          ScrollViewer.HorizontalScrollBarVisibility="Auto" 
                          CanUserAddRows="False"
                          CanUserDeleteRows="False"
                          CanUserReorderColumns="False"
                          CanUserResizeRows="False"
                          IsReadOnly="True"
                          SelectionMode="Single" 
                          FontSize="25"
                          ItemsSource="{Binding}">
 
                    <DataGrid.Resources>
                        <Style TargetType="DataGridRow">
                            <EventSetter Event="MouseDoubleClick" Handler="Row_DoubleClick"/>
                        </Style>
                    </DataGrid.Resources>
 
                    <DataGrid.Columns>
 
                        <DataGridTextColumn Header="ИД"
                                            Binding="{Binding id}"
                                            Width="3*"/>
 
                        <DataGridTextColumn Header="Серийный номер"
                                            Binding="{Binding sn}"
                                            Width="10*"/>
 
                        <DataGridTextColumn Header="OBIS"
                                            Binding="{Binding obis}"
                                            Width="10*"/>
 
                        <DataGridTextColumn Header="Date"
                                            Binding="{Binding date}"
                                            Width="10*"/>
 
                        <DataGridTextColumn Header="EvCode"
                                            Binding="{Binding evcode}"
                                            Width="10*"/>
 
                    </DataGrid.Columns>
 
                </DataGrid>


What I have tried:

Trying to do something in editing, you just need to change the attribute of the table and update the View:
C#
private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (tableNoRead.SelectedItem != null)
            {
                //db.PushTables.Add(new PushTable() { id = 444, sn = "sd", obis = "dsa", evcode = 213, date = "sdsad" });
                //db.SaveChanges();
                //tableNoRead.ItemsSource = db.PushTables.ToList();
                db.PushTables.Remove(tableNoRead.SelectedItem as PushTable);
                db.SaveChanges();
            }
        }
Posted
Comments
Graeme_Grant 24-Aug-22 7:56am    
and your question? What errors are you seeing?
[no name] 24-Aug-22 11:23am    
This should be some asynchronous operation out there somewhere instead of a DataGrid double-click.

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