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;
Hope you can help thanks.
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`.
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
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;
{ 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
Thank you very much for this wonderful essay; I look forward to reading more of your writings.
- 4 Replies
- 4 Participants
-
MI Mickie Ivan Mamongay
- Jan 15, 2025 08:44 AM UTC
- Apr 3, 2025 07:37 AM UTC