Can't display label text

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I have the following method where I need to display which database is
being processed, however, the label lblDatabase dosn't seem to work until the
end.

private void AddPathAndCallCompactDB(string dbFolder, string systemDB,
string UserID, string Pwd, string dbFileName)
{
FileInfo dbFileInfo = new FileInfo(dbFolder + dbFileName);
this.lblDatabase.Text = dbFileInfo.Name;
if (dbFileInfo.Exists)
{
CompactDB(systemDB, UserID, Pwd, dbFileInfo.FullName);
progressBar.Value++;
}
else
//Cannot find database file
{
MessageBox.Show("Cannot find the database " + dbFileInfo.FullName + "\n" +
"\n" +
"Check the database name (and path, if specified) to make sure it exists." +
"\n" + "\n" +
"The other databases will be compacted.",
messageHeader,MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
}
 
Things to check:

1. Is the label property visible set to true?

2. Are the font color and back colour the same?

3. If you change it to display a message box is there actually a name in the
property?

FileInfo dbFileInfo = new FileInfo(dbFolder + dbFileName);
//this.lblDatabase.Text = dbFileInfo.Name;
MessageBox.Show ( "The value of dbFileInfo.Name is: " + dbFileInfo.Name );

4. Are the label width and height greater than zero?

Hope that helps.

Dan.
 
Hi Dan thanks for the help. I tried

//this.lblDatabase.Text = dbFileInfo.Name;
MessageBox.Show ( "The value of dbFileInfo.Name is: " + dbFileInfo.Name );

which works ok, I then tried

this.lblDatabase.Text = dbFileInfo.Name;
MessageBox.Show ( "The value of dbFileInfo.Name is: " + dbFileInfo.Name );

which also works. However,

this.lblDatabase.Text = dbFileInfo.Name;
//MessageBox.Show ( "The value of dbFileInfo.Name is: " + dbFileInfo.Name );

does not work. This is driving me crazy!! Any other thoughts anybody?
 
what about this:

this.lblDatabase.Text = "Hello World";


finally, in the designer, if the label is blank make sure you can put text
in it.

Thanks.

Dan
 
this.lblDatabase.Text = "Hello World"; only works with the line

MessageBox.Show ( "The value of dbFileInfo.Name is: " + dbFileInfo.Name );

I've also setup a new button on the form with

private void button1_Click(object sender, System.EventArgs e)
{
lblDatabase.Text = "Hello World";
}

which works OK. Does the
this.lblDatabase.Text = dbFileInfo.Name;
need an event to fire to display the value? This can't be correct!
 
Managed to solve this by using

lblDatabase.Text = dbFileInfo.Name;
lblDatabase.Refresh();

Thanks
 
Oh right, did you go off and do more operations after this?

Remember that redraws are not do instantly. If you want to a redraw then
call Refresh(). I generally don't call Refresh() on individual controls, but
rather the parent form.

glad you got it sorted!
 
jez123456 said:
Managed to solve this by using

lblDatabase.Text = dbFileInfo.Name;
lblDatabase.Refresh();

So you are doing more processing after this? If it is taking a while
then perhaps you should be doing the processing in a thread.
 
Back
Top