Refresh form / form controls in backdrop?

  • Thread starter Thread starter Brian Basquille
  • Start date Start date
B

Brian Basquille

Hey there all,

Fairly easy question for a C# expert, i assume! Am still working on my Photo
Album.

On frmBrowsePhotos, i have a listBox (photosList) containing photoID's from
a table in an Access Database. I click 'Add Photo' on that form and after
the OpenFileDialog (etc.), it asks me to save some information about the
photo (caption etc.) on a new form (frmAddPhotoInfo) opened up in front of
the previous (frmBrowsePhotos).

On frmAddPhotoInfo, when i hit the OK button to confirm the new photo and
it's information - i want the ListBox to be refreshed in the background to
display the new photoID.

Basically, i want to refresh that form (frmBrowsePhotos) and / or repopulate
that ListBox (listPhotos)?

Many thanks in advance.

Brian
 
Hey Brian,

Could you please elaborate on what you mean by saying 'refresh in the
background'?
You can for example run a query against the database on a worker thread or
by using BeginInvoke on a delegate, but everything you do to the form and
the controls should happen on the UI thread.
 
Dmitriy,

Thanks for the response. I don't think what i require would be as
complicated as what you've suggested.

Basically, it involves two forms - BrowsePhotos and AddNewPhotoInfo.

When i choose to add a 'New Photo' on the BrowsePhotos form, the user
chooses the photo and AddNewPhotoInfo form then pops up to allow the user to
enter information about the photo to be recorded (Caption etc.). All this
time however, the BrowsePhotos form remains in the background showing all
the existing photo id's (listPhotos) in the database.

When the user presses the 'OK' on the AddNewInfo form, a SQL statement is
executed to save the new Photo information (and a unique ID to the
database). However, i need to exit the BrowsePhotos form and launch it again
for it to reflect the newly added photo (and it's id) in the listPhotos
ListBox.

All i basically require is when the user pressed 'OK' on the
AddNewPhotoForm, the listPhotos listBox is automatically refreshed on the
BrowsePhotos form.

I could presumably make the listPhotos public and use something along the
lines of:

BrowsePhotos browsePhotos = new BrowsePhotos();
browsePhotos.listPhotos.Refresh();
browsePhotos.Show();

But the problem with that is i want it to update on the existing
BrowsePhotos form.. and not create a new form.

Hope this clarifies my problem a bit more!

Brian

Dmitriy Lapshin said:
Hey Brian,

Could you please elaborate on what you mean by saying 'refresh in the
background'?
You can for example run a query against the database on a worker thread or
by using BeginInvoke on a delegate, but everything you do to the form and
the controls should happen on the UI thread.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Brian Basquille said:
Hey there all,

Fairly easy question for a C# expert, i assume! Am still working on my
Photo Album.

On frmBrowsePhotos, i have a listBox (photosList) containing photoID's
from a table in an Access Database. I click 'Add Photo' on that form and
after the OpenFileDialog (etc.), it asks me to save some information
about the photo (caption etc.) on a new form (frmAddPhotoInfo) opened up
in front of the previous (frmBrowsePhotos).

On frmAddPhotoInfo, when i hit the OK button to confirm the new photo and
it's information - i want the ListBox to be refreshed in the background
to display the new photoID.

Basically, i want to refresh that form (frmBrowsePhotos) and / or
repopulate that ListBox (listPhotos)?

Many thanks in advance.

Brian
 
Brian,
All i basically require is when the user pressed 'OK' on the
AddNewPhotoForm, the listPhotos listBox is automatically refreshed on the
BrowsePhotos form.

I assume you have a button 'Add new photo' on frmBrowsePhotos.

In this case, in the button's Click handler, you should first launch the
'Add new photo' form in the modal mode.
After the user closes the frmAddNewInfo, provided the DialogResult is OK,
you ask the frmAddNewInfo instance for the photo file name and ID given (you
will need to add a couple of public properties to frmAddNewInfo for that).
Then, as the control flow has returned to the Click event handler which is a
part of frmBrowsePhotos, we can now just add a new item to the listbox.

In pseudocode

void cmdAddNew_Click(object sender, EventArgs e)
{
frmAddNewInfo newForm = new frmAddNewInfo();
DialogResult result = frmAddNewInfo.ShowModal();


if (DialogResult.OK == result)
{
listBox.AddPhotoItem(newForm.ID, newForm.FileName);
}

newForm.Dispose();
}

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Brian Basquille said:
Dmitriy,

Thanks for the response. I don't think what i require would be as
complicated as what you've suggested.

Basically, it involves two forms - BrowsePhotos and AddNewPhotoInfo.

When i choose to add a 'New Photo' on the BrowsePhotos form, the user
chooses the photo and AddNewPhotoInfo form then pops up to allow the user
to enter information about the photo to be recorded (Caption etc.). All
this time however, the BrowsePhotos form remains in the background showing
all the existing photo id's (listPhotos) in the database.

When the user presses the 'OK' on the AddNewInfo form, a SQL statement is
executed to save the new Photo information (and a unique ID to the
database). However, i need to exit the BrowsePhotos form and launch it
again for it to reflect the newly added photo (and it's id) in the
listPhotos ListBox.

All i basically require is when the user pressed 'OK' on the
AddNewPhotoForm, the listPhotos listBox is automatically refreshed on the
BrowsePhotos form.

I could presumably make the listPhotos public and use something along the
lines of:

BrowsePhotos browsePhotos = new BrowsePhotos();
browsePhotos.listPhotos.Refresh();
browsePhotos.Show();

But the problem with that is i want it to update on the existing
BrowsePhotos form.. and not create a new form.

Hope this clarifies my problem a bit more!

Brian

Dmitriy Lapshin said:
Hey Brian,

Could you please elaborate on what you mean by saying 'refresh in the
background'?
You can for example run a query against the database on a worker thread
or by using BeginInvoke on a delegate, but everything you do to the form
and the controls should happen on the UI thread.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Brian Basquille said:
Hey there all,

Fairly easy question for a C# expert, i assume! Am still working on my
Photo Album.

On frmBrowsePhotos, i have a listBox (photosList) containing photoID's
from a table in an Access Database. I click 'Add Photo' on that form and
after the OpenFileDialog (etc.), it asks me to save some information
about the photo (caption etc.) on a new form (frmAddPhotoInfo) opened up
in front of the previous (frmBrowsePhotos).

On frmAddPhotoInfo, when i hit the OK button to confirm the new photo
and it's information - i want the ListBox to be refreshed in the
background to display the new photoID.

Basically, i want to refresh that form (frmBrowsePhotos) and / or
repopulate that ListBox (listPhotos)?

Many thanks in advance.

Brian
 
Sorry i'm only getting back to you now Dmitriy.

Been very busy at college... #

Cheers for the advice on the Modal mode. Didn't even think about using that!

Much appreciated!


Dmitriy Lapshin said:
Brian,
All i basically require is when the user pressed 'OK' on the
AddNewPhotoForm, the listPhotos listBox is automatically refreshed on the
BrowsePhotos form.

I assume you have a button 'Add new photo' on frmBrowsePhotos.

In this case, in the button's Click handler, you should first launch the
'Add new photo' form in the modal mode.
After the user closes the frmAddNewInfo, provided the DialogResult is OK,
you ask the frmAddNewInfo instance for the photo file name and ID given
(you will need to add a couple of public properties to frmAddNewInfo for
that). Then, as the control flow has returned to the Click event handler
which is a part of frmBrowsePhotos, we can now just add a new item to the
listbox.

In pseudocode

void cmdAddNew_Click(object sender, EventArgs e)
{
frmAddNewInfo newForm = new frmAddNewInfo();
DialogResult result = frmAddNewInfo.ShowModal();


if (DialogResult.OK == result)
{
listBox.AddPhotoItem(newForm.ID, newForm.FileName);
}

newForm.Dispose();
}

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Brian Basquille said:
Dmitriy,

Thanks for the response. I don't think what i require would be as
complicated as what you've suggested.

Basically, it involves two forms - BrowsePhotos and AddNewPhotoInfo.

When i choose to add a 'New Photo' on the BrowsePhotos form, the user
chooses the photo and AddNewPhotoInfo form then pops up to allow the user
to enter information about the photo to be recorded (Caption etc.). All
this time however, the BrowsePhotos form remains in the background
showing all the existing photo id's (listPhotos) in the database.

When the user presses the 'OK' on the AddNewInfo form, a SQL statement is
executed to save the new Photo information (and a unique ID to the
database). However, i need to exit the BrowsePhotos form and launch it
again for it to reflect the newly added photo (and it's id) in the
listPhotos ListBox.

All i basically require is when the user pressed 'OK' on the
AddNewPhotoForm, the listPhotos listBox is automatically refreshed on the
BrowsePhotos form.

I could presumably make the listPhotos public and use something along the
lines of:

BrowsePhotos browsePhotos = new BrowsePhotos();
browsePhotos.listPhotos.Refresh();
browsePhotos.Show();

But the problem with that is i want it to update on the existing
BrowsePhotos form.. and not create a new form.

Hope this clarifies my problem a bit more!

Brian

Dmitriy Lapshin said:
Hey Brian,

Could you please elaborate on what you mean by saying 'refresh in the
background'?
You can for example run a query against the database on a worker thread
or by using BeginInvoke on a delegate, but everything you do to the form
and the controls should happen on the UI thread.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Hey there all,

Fairly easy question for a C# expert, i assume! Am still working on my
Photo Album.

On frmBrowsePhotos, i have a listBox (photosList) containing photoID's
from a table in an Access Database. I click 'Add Photo' on that form
and after the OpenFileDialog (etc.), it asks me to save some
information about the photo (caption etc.) on a new form
(frmAddPhotoInfo) opened up in front of the previous (frmBrowsePhotos).

On frmAddPhotoInfo, when i hit the OK button to confirm the new photo
and it's information - i want the ListBox to be refreshed in the
background to display the new photoID.

Basically, i want to refresh that form (frmBrowsePhotos) and / or
repopulate that ListBox (listPhotos)?

Many thanks in advance.

Brian
 
Back
Top