I'm writing an application with C# Winforms and using a WebBrowser
object to display text files.
I have a DataGridView
which shows me all the files I have added before, and every click on a Data Row activates webBrowser.Navigate(FilePath)
.
The thing is it shows me the text file properly in the first time after clicking the first .txt in the DataGrid, but after it its just writing me:
the page could not be displayed
...in the WebBrowser
panel.
I tried to added this code before it loaded another text file:
webBrowser.Navigate("about:blank");
System.Windows.Forms.Application.DoEvents();
but it doesn't help.
Edit: After clicking on a RowCell
in DataGridView
I'm calling this function with the file full path:
private byte LoadDoc(string sFileName)
{
fInfo = new FileInfo(sFileName);
if (fInfo.Extension.ToUpper().StartsWith(".TXT"))
{
pnlBrowser.Visible = true;
webBrowser.Navigate(fInfo.FullName);
if (webBrowser.Document != null)
{
webBrowser.Document.Encoding = "iso-8859-8-i";
}
return 0;
}
}
Edit: This is the DataGridView
CellClick
code:
private void dgvDetails_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && dgvDetails.Rows.Count > 0)
{
if (e.ColumnIndex == 0)
{
DataGridViewCell myCell = dgvDetails.Rows[e.RowIndex].Cells[0];
if (Convert.ToBoolean(myCell.Value) == true)
myCell.Value = false;
else
myCell.Value = true;
}
this.Cursor = Cursors.WaitCursor;
txtFileDesc.Text = dgvDetails.Rows[e.RowIndex].Cells["C90FILDS"].Value.ToString();
// clear temp values
ClearTempVals();
this.Cursor = Cursors.Default;
System.Windows.Forms.Application.DoEvents();
this.Cursor = Cursors.WaitCursor;
// store temp values in case update required
sd_CustNum = Convert.ToInt32(dgvDetails.Rows[e.RowIndex].Cells["C90CSTID"].Value);
sd_ProcId = Convert.ToInt64(dgvDetails.Rows[e.RowIndex].Cells["C90CSTID"].Value);
sd_ActivityId = Convert.ToInt32(dgvDetails.Rows[e.RowIndex].Cells["C90CSTID"].Value);
sd_FileId = Convert.ToString(dgvDetails.Rows[e.RowIndex].Cells["C90FILID"].Value);
sd_FileDesc = Convert.ToString(dgvDetails.Rows[e.RowIndex].Cells["C90FILDS"].Value);
sd_Mutag = Convert.ToString(dgvDetails.Rows[e.RowIndex].Cells["C90MUTAG"].Value);
sd_Dealer = Convert.ToString(dgvDetails.Rows[e.RowIndex].Cells["C90DEAL"].Value);
sd_DocNum = Convert.ToInt32(dgvDetails.Rows[e.RowIndex].Cells["C90DOCID"].Value);
sd_DocType = Convert.ToByte(dgvDetails.Rows[e.RowIndex].Cells["C90DOCTP"].Value);
sd_ScanDate = Convert.ToInt32(dgvDetails.Rows[e.RowIndex].Cells["C90OPDT"].Value);
sd_ScanTime = Convert.ToInt32(dgvDetails.Rows[e.RowIndex].Cells["C90OPTM"].Value);
sd_ScanUser = Convert.ToString(dgvDetails.Rows[e.RowIndex].Cells["C90OPUS"].Value);
sd_SibatIdkun = Convert.ToString(dgvDetails.Rows[e.RowIndex].Cells["C90UPSBA"].Value);
sd_IdkunDate = Convert.ToInt32(dgvDetails.Rows[e.RowIndex].Cells["C90UPDT"].Value);
sd_IdkunTime = Convert.ToInt32(dgvDetails.Rows[e.RowIndex].Cells["C90UPTM"].Value);
sd_IdkunUser = Convert.ToString(dgvDetails.Rows[e.RowIndex].Cells["C90UPUS"].Value);
if (LoadDoc(dgvDetails.Rows[e.RowIndex].Cells["C90FILID"].Value.ToString()) > 0)
{
ClearTempVals();
_ErrMsg = "Error Accrues";
return;
}
System.Threading.Thread.Sleep(250);
BtnSave.Enabled = true;
btnDelete.Enabled = true;
}
else // trying to sort columns by clicking headers
{
// clear webbrowser and selected rows
webBrowser1.Navigate("about:blank");
dgvDetails.ClearSelection();
dgvDetails.CurrentCell = null;
txtFileDesc.Text = "";
BtnSave.Enabled = false;
ClearTempVals();
}
}
Edit: This is what WebBrowser object
contains (in debug mode) after calling the second text file:
Please help me.