My problem is, when I create a button that refreshes data grid when the new auction or delete auction is clicked, nothing happens at all, or even some syntax error shows up. So I need:
Refresh button, which I made through XAML
.
So when the delete button is clicked I need a row deleted, that I made too.
But, my refresh doesn't work. I need to log out from the application and log in again, to make some changes. I don't really know how to do this.
I'll provide some pictures down below, and also some code.
Default log in:
Adding a sale or deleting a sale, then logging out and logging back in:
I tried making a data grid that auto-updates. I tried making this button, I got a few syntax errors, I also tried adding dgGridView.Items.Refresh()
, didn't help either.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
BindDataGrid();
}
private void BindDataGrid()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnString"].ToString();
conn.Open();
SqlCommand comm = new SqlCommand("SELECT * FROM AuctionTbl2", conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(comm);
da.Fill(ds);
dgGrid.ItemsSource = ds.Tables[0].DefaultView;
dgGrid.Items.Refresh();
}
private void LogoutBtn_Click(object sender, RoutedEventArgs e)
{
MainWindowGuest mwg = new MainWindowGuest();
mwg.Show();
this.Close();
MessageBox.Show("You have been logged out.");
}
private void DeleteBtn_Click(object sender, RoutedEventArgs e)
{
try
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString =
ConfigurationManager.ConnectionStrings["ConnString"].ToString();
conn.Open();
string query = "delete from AuctionTbl2";
SqlCommand comm = new SqlCommand(query, conn);
comm.ExecuteNonQuery();
MessageBox.Show("Deleted");
conn.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void AddNew_Click(object sender, RoutedEventArgs e)
{
NewDeleteWindow newDeleteWindow = new NewDeleteWindow();
newDeleteWindow.DataContext = new NewSaveButton();
newDeleteWindow.ShowDialog();
}
}
}
I expect to make a refreshment when the sale is added or deleted, on a refresh button or without it, doesn't matter. Just to refresh this grid. Thank you all.