Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Adding a Hyperlink Column in DataGrid at Runtime
3 replies. Latest Post by shamrat231 on November 11, 2008.
(0)
a_anandr...
Member
15 points
163 Posts
11-11-2008 3:18 AM |
Hi
I am generating a DataGrid at runtime. one of the Column is Hyperlink. How to add a Column as a HyperLink? Do we have to use DataGridTemplateColumn?
Thanks
Anandraj.A.
shamrat231
Contributor
4667 points
595 Posts
11-11-2008 3:33 AM |
Create a hyperlink button and add it to
HyperlinkButton hyperbut = new HyperlinkButton();
hyperbut.Content = "Nº Int";
hyperbut.Tag = "nint";
hyperbut.Click += new RoutedEventHandler(Sort_Click);
hyperbut.TextDecorations = TextDecorations.Underline;
Create a templateColumn
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();templateColumn.Header = "Birthday";
Add the hyperlink button to the template column
If this post was helpful then please 'Mark as Answer'
Sharker Khaleed Mahmud (MCPD)
11-11-2008 4:36 AM |
I am working on Silverlight 2 and it does not shows the TextDecoration property for the HyperLink. I don't even find Add Method in DataGridTemplateColumn to add this Hyperlink. Can you please give me some link where it is explained?
11-11-2008 7:49 AM |
Check this link.
http://silverlight.net/forums/t/20690.aspx
Here it adds a stackpanel to the DataGridTemplateColumn.
Look at the bottom of the page.
stackPanelTemplate = (DataTemplate)XamlReader.Load(String.Format("<DataTemplate {0}><StackPanel VerticalAlignment='Center' Margin='4,8,4,4' Orientation=\"Vertical\" /></DataTemplate>", defaultNamespace));
authorsColumn = new DataGridTemplateColumn();authorsColumn.Header = "Authors";authorsColumn.IsReadOnly = true;authorsColumn.CellTemplate = StackPanelTemplate;
Same procedure could be followed for your HyperlinkButton.
Hope this helps,