GridHyperlinkColumn cannot be edited

Hi, 

Is it possible to edit GridHyperlinkColumn? 

Here in the screenshot I cannot enter a text in SI Number when clicking add invoice, despite allowing the editing to true.

dgvSales.Columns[i] = new GridHyperlinkColumn()

{

    MappingName = "*SI Number",

    HeaderText = "*SI Number",

    Width = 150,

    AllowEditing = true

};

break;

Image_5074_1736930437452

Hope you can help thanks.



4 Replies

MS Malini Selvarasu Syncfusion Team January 16, 2025 10:58 AM UTC

Hi  Mickie Ivan Mamongay,

Based on the information provided, we understand that you attempted to edit the `GridHyperLinkColumn`. However, this column type does not support editing and, as a result, cannot enter edit mode. This behavior is inherent to the `GridHyperLinkColumn`.  
To better understand your requirements and provide an accurate solution, could you please share the reason for needing to edit the `GridHyperLinkColumn`? Your input will help us address your needs more effectively. Thank you for your cooperation.
Regards,
Malini Selvarasu


MI Mickie Ivan Mamongay replied to Malini Selvarasu January 16, 2025 05:12 PM UTC

Hi,

I aim to enable users to directly input a hyperlink when adding a new row in the sfDataGridView control, as well as allow them to edit the hyperlink later if it was entered incorrectly. I understand the limitations of the GridHyperLinkColumn. Could you suggest a possible workaround that would allow users to input hyperlinks directly?

Thanks




SG Santhosh Govindasamy Syncfusion Team January 17, 2025 02:28 PM UTC

Hi Mickie Ivan Mamongay,

As we previously mentioned, the `GridHyperLinkColumn` does not support editing and, as a result, cannot enter edit mode. Your requirement can be achieved by customizing the `GridTextBoxCellRenderer` based on the `GridHyperLinkColumn` and loading the data into the `GridTextColumn`. In this renderer, modify the text color and font style according to your requirements.


Code Snippet:

this.sfDataGrid1.CellRenderers.Remove("TextBox");

this.sfDataGrid1.CellRenderers.Add("TextBox", new GridTextBoxCellRendererExt());



 

public class GridTextBoxCellRendererExt : GridTextBoxCellRenderer

{

    protected override void OnRender(Graphics paint, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex)

    {

        if (column.GridColumn.MappingName == "Country")

        {

            style.TextColor = Color.Blue; // Make the text blue

           

            style.Font = new GridFontInfo(new Font(style.GetFont().FontFamily, style.GetFont().Size, style.GetFont().Style | FontStyle.Underline));

 

        }

        base.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex);

    }

   

}




Additionally, change the font to bold on mouse hover using the `QueryCellStyle` event. Finally, by using the cell click event, you can open the hyperlink in a search engine based on the clicked cell.

Code Snippet:

sfDataGrid1.QueryCellStyle += SfDataGrid1_QueryCellStyle;

sfDataGrid1.CellClick += SfDataGrid1_CellClick;


private void SfDataGrid1_QueryCellStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryCellStyleEventArgs e)

 {

     if (e.Column.MappingName == "Country")

     {

         if (e.RowIndex == hoveredRowIndex)

         {

            

             e.Style.Font.FontStyle=FontStyle.Bold;

            

         }

     }

 }

 

private void SfDataGrid1_CellClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs e)

        {

            if(e.DataColumn.GridColumn.MappingName== "Country" &&e.DataRow.RowData!=null)

            {

                // Get the value of the cell

                var countryValue = e.DataRow.RowData.GetType()

                                    .GetProperty("Country")?

                                    .GetValue(e.DataRow.RowData, null)?

                                    .ToString();

 

                if (!string.IsNullOrEmpty(countryValue))

                {

                   

 

                    // Construct the search URL

                    string url = $"https://en.wikipedia.org/wiki/{countryValue}";

 

                    // Specify the full path to chrome.exe

                   

 

                    // Open the URL.

                    Process process = new Process();

                    process.StartInfo.FileName = "iexplore";

                    process.StartInfo.Arguments = url;

                    process.Start();

                }

            }

 

        }


For your reference, we have attached the sample. Please review it.

Regards,
Santhosh.G



Attachment: SfDatagrid_Demo_4e21c250.zip


HL Harry Lu April 3, 2025 07:37 AM UTC

Thank you very much for this wonderful essay; I look forward to reading more of your writings.


Loader.
Up arrow icon