Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
140
Creating a hyperlink while autogeneratecolumns=true
posted

I have a xamgrid with autogeneratecolumns = true. But in runtime I need to show a hyperlinkbutton instead of text based on the cell value.

Here is the code I tried:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

private

 

 

void siteGrid_CellControlAttached(object sender, Infragistics.Controls.Grids.CellControlAttachedEventArgs e)

{

 

 

 

if (e.Cell.Control != null)

{

 

 

 

SiteEntity se = e.Cell.Row.Data as SiteEntity;

 

 

 

if (se != null && !e.IsDirty)

{

 

 

if (double.Parse(se.Latitude) > 42)

{

 

 

 

 

if (e.Cell.Column.Key == "Latitude")

      e.Cell.Control.Foreground =

 

new SolidColorBrush(Colors.Red);

 

 

 

if (e.Cell.Column.Key == "SiteID")

{

 

 

 

HyperlinkButton link = new HyperlinkButton();

link.Content = e.Cell.Value;

link.NavigateUri =

 

new Uri(http://www.google.com);

e.Cell.Control.Content = link;

}

e.IsDirty =

 

true;

}}}}

When I debug it shows the cell content as hyperlink button. But in the end I see only the text in the grid. There is no link available. Could you please tell me how to achieve this?

Thanks.

  • 40030
    Offline posted

    Hi, 

    The approach you're taking is going to lead to a bunch of problems, including perf issues.  Is the dataType of your column a specific Type. If so, you can use our ColumnTypeMapping feature: 

    http://help.infragistics.com/NetAdvantage/Silverlight/2011/1/CLR4.0/?page=SL_xamGrid_Change_Column_Type_Mapping.html

    If it's the same Type as other columns which should be TextColumns, then you have 2 options. 

    1. Manually specify your columns in xaml or in the code behind. 

    2. Create a custom column, that generates a TextBlock or Hyperlink based on your criteria. Then you'd use the columnTypeMapping feature to point to your column for that specific type. 

    -SteveZ

  • 140
    posted

    Here is my recent observation:

    The initial load didn't show any links. But when I scroll down I'm able to see some links. If I scroll up now I see the links in the first page also. But it's very random. It's not happening for all the rows that met the condition. For few rows I see the link. Could anyone please point out what I'm missing here?