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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

opend pdf file with with associate application

Thread ID:

Created:

Updated:

Platform:

Replies:

144452 May 7,2019 10:57 AM UTC May 13,2019 06:15 AM UTC WinForms 5
loading
Tags: SfDataGrid
anas
Asked On May 7, 2019 11:12 AM UTC

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;





Jagadeesan Pichaimuthu [Syncfusion]
Replied On 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 


anas
Replied On 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);
        }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////






Jagadeesan Pichaimuthu [Syncfusion]
Replied On 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

anas
Replied On 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);

        }


Jagadeesan Pichaimuthu [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon