C# WinForm Gridview problem
I have a C# WinForm application which renders a PDF to the viewer on clicking a button in gridview
Clicking the Open button cause the following code to be run:
#region "gvProcessSheet_CellValidating"
private void gvProcessSheet_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (!gvProcessSheet.ReadOnly &&
e.ColumnIndex == (int)gvCols.btnOpenWorkInstructionPDF &&
(!(string.IsNullOrEmpty(gvProcessSheet.Rows[e.RowIndex].Cells[(int)gvCols.WorkInstructionUID].EditedFormattedValue.ToString()))))
{
// Ignore clicks that are not on button cells.
if (e.RowIndex < 0) return;
gvProcessSheet.CellValidating -= gvProcessSheet_CellValidating;
DataGridViewRow gvr = gvProcessSheet.Rows[e.RowIndex];
#region "Open PDF Click"
#region "SetSelectionParameters"
AppPropertiesCS.InitSelectWorkInstructionInfo();
AppPropertiesCS.p_WorkInstructionInfoUID = Convert.ToInt32(gvProcessSheet.Rows[e.RowIndex].Cells[(int)gvCols.WorkInstructionUID].EditedFormattedValue.ToString());
AppPropertiesCS.p_WorkInstructionInfo_SelectWorkInstructionUIDFlag = true;
AppPropertiesCS.p_norecordsfoundallowedflag = false;
#endregion
#region "Load Work Instruction Info"
DataTable dt = new DataTable();
if (!(BusinessLogicCS.LoadWorkInstructionInfo(ref dt)))
{
//return;
}
#endregion
DataRow dr = dt.Rows[0];
byte[] PDFBytes = (byte[])dr["attachment"];
LoadPdf(PDFBytes);
#region "Setup Form"
pnlTopLevelProcessSheetInfo.Visible = false;
gvProcessSheet.Visible = false;
pnlPDFViewer.Visible = true;
pdfViewer1.Visible = true;
btnPDFViewerClose.Visible = true;
lblmessage.Visible = false;
AppPropertiesCS.p_ExitCellEnterFlag = true;
gvProcessSheet.CellValidating -= gvProcessSheet_CellValidating;
#endregion
}
#endregion
#region "Load PDF"
public void LoadPdf(byte[] pdfBytes)
{
//* Create PDF Memory Stream
var pdfstream = new MemoryStream(pdfBytes);
// Create PDF Document
var pdfDocument = PdfDocument.Load(pdfstream);
// Load PDF Document into WinForms Control
pdfViewer1.Document = pdfDocument;
}
#endregion
The PDF is displayed in the viewer:
Now when I click on the close button the gridview is redisplayed. The following code is run:
private void btnPDFViewerClose_Click(object sender, EventArgs e) { pnlTopLevelProcessSheetInfo.Visible = true; gvProcessSheet.Visible = true; pnlPDFViewer.Visible = false; pdfViewer1.Visible = false; btnPDFViewerClose.Visible = false; lblmessage.Visible = true; // FindNextPendingItem(); }
The gridview is rendered but only accepts one digit. The user scans in there employee badge, but the gridview only excepts one digit. Please advise on how to fix this problem. Thanks Paul
I'm not sure how this could be caused by the PdfiumViewer project. Would you be able to create a (small) project that reproduces this issue? The easiest would be to fork the PdfiumViewer project and modify the Demo project to reproduce this issue. Then I could have a look at your fork and see how this could be solved.