Skip to main content

Microsoft Silverlight

Answered Question Adding a Hyperlink Column in DataGrid at RuntimeRSS Feed

(0)

a_anandraj@hotmail.com
a_anandr...

Member

Member

15 points

163 Posts

Adding a Hyperlink Column in DataGrid at Runtime

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
shamrat231

Contributor

Contributor

4667 points

595 Posts

Re: Adding a Hyperlink Column in DataGrid at Runtime

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)

 

Dhaka, Bangladesh
LinkedIn :: SL Profile :: Blog

a_anandraj@hotmail.com
a_anandr...

Member

Member

15 points

163 Posts

Re: Adding a Hyperlink Column in DataGrid at Runtime

Hi

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?

Thanks

Anandraj.A.

 

shamrat231
shamrat231

Contributor

Contributor

4667 points

595 Posts

Answered Question

Re: Adding a Hyperlink Column in DataGrid at Runtime

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,

If this post was helpful then please 'Mark as Answer' 

Sharker Khaleed Mahmud (MCPD)

Dhaka, Bangladesh
LinkedIn :: SL Profile :: Blog
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities