w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
how to insert update delete within the wpf datagrid itself using mysql i.e editable datagrid

This can be done, but takes some effort. It's not straight forward, meaning you have to bind the data source with the Grid and then implement the delete, update functions. there are lot of samples on the net.

The link asked to follow : Example link

You have to do the changes on your code above;

  1. In the main window constructor do the following

    public MainWindow()
    {
        InitializeComponent();
        DataTable dataTable =
    (DataTable((DataSourceProvider)FindResource("userdata")).Data;
        dataTable.RowChanged += new
    DataRowChangeEventHandler(dataTable_RowChanged);
        dataTable.RowDeleted += new
    DataRowChangeEventHandler(dataTable_RowChanged);
    }
    
  2. In the rowchanged event;

    private void dataTable_RowChanged(object sender,
    DataRowChangeEventArgs e)
    {
        UpdateDBIssues();
    }
    

I am not sure why you do this check (!changingTitle), In your case it seems not necessary because you haven't used a combo box or a list to change the population of the Grid as is in the example. I tested the code and it works. So with these changes, you will be fine. If it still does not work, Take one command at a time and debug to catch the error. Hope this helps.

XAML: something similar to

 <Grid DataContext="{StaticResource dataTable}">
    <DataGrid  ItemsSource="{Binding Mode=OneWay}"
AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True"
                x:Name="testDataGrid" Margin="0,0,0,0"
HorizontalAlignment="Center">

      <DataGrid.Columns>

                    <!--Databound columns-->

       </DataGrid.Columns>

    </DataGrid>
</Grid>




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.