I've a form that runs a query from a DataGridView
on a button click. The below code works how I expect it to;
- Opens a form that says "Please Wait while query runs"
- Runs query
- Closes form when loaded and then fill the DataGridView with the data.
I have added a picturebox with simple gif - purely for the UI and the user to see it is working. But the gif doesn't actually spin - just shows as a picture. Testing it, if I run it on a form on its own it is fine, I can only hazard a guess that the query running is stopping it from working how it should.
PleaseWaitForm pleaseWait = new PleaseWaitForm();
try
{
pleaseWait.Show();
Application.DoEvents();
this.singleCenTableAdapter.Fill(this.singleCenData.SingleCenTable, ((System.DateTime)(System.Convert.ChangeType(txtBookFrom.Text, typeof(System.DateTime)))), ((System.DateTime)(System.Convert.ChangeType(txtBookTo.Text, typeof(System.DateTime)))));
int RowC = singleCenTableDataGridView.RowCount;
pleaseWait.Close();
if (RowC == 0)
{
MessageBox.Show(GlobVar.NoResults, "", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
pleaseWait.Close();
}
catch (System.Exception exc)
{
GlobVar.vid.Open();
var LogName = GlobVar.LoginName.ExecuteScalar();
GlobVar.vid.Close();
MessageBox.Show
(
"An error has occured " + LogNam + ". Please try again. \n\n" +
exc.Message, "An error has occured", MessageBoxButtons.OK, MessageBoxIcon.Warning
);
}
finally
{
pleaseWait.Close();
}
The "Please Wait" form is just a label & picture so there is nothing but the Initalize in there at the minute ;
public PleaseWaitForm()
{
InitializeComponent();
}
Does anybody have any ideas on how to tackle this to make it work correct? Or anything particular that I am doing wrong? I know for the most part I might get a bit of stick for using Application.DoEvents()
anyway, but any help is appreciated!