We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

opend pdf file with with associate application

c# winform

What I want is to open a file via a "GridButtonColumn" instead of using "GridHyperlinkColumn"

            (sfDataGrid1.Columns["PDF_File"] as GridHyperlinkColumn).HyperlinkOpenArea = HyperlinkOpenArea.Cell;
            (this.sfDataGrid1.Columns["PDF_File"] asGridHyperlinkColumn).HyperlinkOpenBehavior = HyperlinkOpenBehavior.SingleClick;





5 Replies

JP Jagadeesan Pichaimuthu Syncfusion Team May 7, 2019 12:41 PM UTC

Hi Anas, 
 
Thanks for using Syncfusion product. 
 
We have checked your requirement to open the file using the GridButtonColumn and you can able to achieve it by using the CellButtonClick event. Please refer the below code snippet which provides the details about how to create a GridButtonColumn and open the file using the CellButtonClick event. When click on any button cell you can able to get the record details by e.Record
 
GridButtonColumn column = new GridButtonColumn() { MappingName = "PDF_File", HeaderText = "PDF_File" };   
this.sfDataGrid1.Columns.Add(column); 
this.sfDataGrid1.CellButtonClick += sfDataGrid1_CellButtonClick; 
 
void sfDataGrid1_CellButtonClick(object sender, CellButtonClickEventArgs e) 
{ 
    var rowData = (e.Record as Syncfusion.WinForms.DataGrid.DataRow).RowData; 
    string fileName = (rowData as OrderInfo).PDF_File; 
 
    /// Implement the code to open the file in button column  
     
} 
 
 
Please refer the below sample for your reference. 
 
 
 
Also you can refer the below documentation to apply the various customizations in GridButtonColumn. 
 
If we misunderstood your requirement, please provide more information regarding the requirement. This would help us to proceed further. 
 
Regards, 
Jagadeesan 



AN anas May 9, 2019 08:49 AM UTC

thank you for your fast reply ...


sorry i should mention before that i`m using datatable to bind to sfdatagrid

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

       private void sfDataGrid2_CellButtonClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellButtonClickEventArgs e)
        {
            string sql = "select *from data";
            DataAccess.ExecuteSQL(sql);
            DataTable dt = DataAccess.GetDataTable(sql);
            

            GridButtonColumn column = new GridButtonColumn() { MappingName = "PDF_File", HeaderText = "PDF_File" };
            this.sfDataGrid2.Columns.Add(column);

            var rowData = (e.Record as Syncfusion.WinForms.DataGrid.DataRow).RowData;

            string fileName =

            Process.Start(fileName);
        }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////







JP Jagadeesan Pichaimuthu Syncfusion Team May 9, 2019 12:21 PM UTC

Hi Anas, 
  
Thanks for your update. 
  
We have checked your provided code snippet, but you should not add the button column inside the CellButtonClick event method. Since each time while click the button, it will add a new button column. So you can add the button column in constructor or form loading method like the below code snippet. 
  
public Form1() 
{ 
    InitializeComponent(); 
    this.sfDataGrid1.DataSource = GetDataTable(); 
    this.sfDataGrid1.Columns.Add(new GridNumericColumn() { MappingName = "EmployeeID", HeaderText = "EmployeeID"}); 
    this.sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "EmployeeName", HeaderText = "EmployeeName" }); 
    this.sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "CustomerID", HeaderText = "CustomerID" }); 
     
    GridButtonColumn column = new GridButtonColumn() { MappingName = "PDF_File", HeaderText = "PDF_File" };             
    this.sfDataGrid1.Columns.Add(column); 
 
    this.sfDataGrid1.CellButtonClick += sfDataGrid1_CellButtonClick; 
 
    this.sfDataGrid1.Columns.Add(new GridDateTimeColumn() { MappingName = "Date", HeaderText = "Order Date", FilterMode = ColumnFilter.DisplayText });             
} 
  
After initialize the datasource, you can add the columns which you want to display in SfDataGrid. And you can hook the CellButtonClick event after initialize the columns like above code snippet. After that implement the CellButtonClick event method to get the current record and please find the code snippet below. 
  
void sfDataGrid1_CellButtonClick(object sender, CellButtonClickEventArgs e) 
{ 
    var rowData = (e.Record as Syncfusion.WinForms.DataGrid.DataRow).RowData as DataRowView; 
    string fileName = rowData["PDF_File"].ToString(); 
 
    /// Implement the code to open the file in button column  
    //Process.Start(fileName); 
} 
  
We have modified the sample with populating the DataTable as DataSource of the SfDataGrid and also implemented the above customization. 
  
  
Let us know whether this helps also if you need any further assistance on this. 
 
Regards, 
Jagadeesan


AN anas May 12, 2019 10:39 AM UTC

Thanks for the quick reply, that's what I was looking for ... Thank you for your support

here is the code I used


////////////////////////////////////////////////////////////////////////////Start Code ////////////////////////////////////////////////////////////////////////////

 

         

this.sfDataGrid1.CellButtonClick += sfDataGrid1_CellButtonClick;



            sfDataGrid1.Columns.Add(new GridButtonColumn()
            {

                MappingName = "PDF_File",
                HeaderText = "File"

            });



private void sfDataGrid1_CellButtonClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellButtonClickEventArgs e)
        {
            var rowData = (e.Record as Syncfusion.WinForms.DataGrid.DataRow).RowData as DataRowView;
            string fileName = rowData["PDF_File"].ToString();
            Process.Start(fileName);

        }



JP Jagadeesan Pichaimuthu Syncfusion Team May 13, 2019 06:15 AM UTC

Hi Anas, 
 
Thanks for your update. 
 
We are glad to know that the provided solution worked at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Jagadeesan

Loader.
Live Chat Icon For mobile
Up arrow icon