This is a migrated thread and some comments may be shown as answers.

Hyperlink Column and Expression col FormatString

1 Answer 85 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David A.
Top achievements
Rank 1
David A. asked on 07 Oct 2013, 03:52 AM
Hi,

I have a few issues and am using version 2012.2.608.20. 

1) Hyperlink column ignores TextAlignment property for column and I have also set this with cell.ContentElement.TextAligment in the CellFormatting event.  Neither will center the column contents.

2) My Hyperlink column does not contain a url, but simply is used to launch a detail form (it is a date field).  The HyperlinkOpened/HyperlinkOpening have no effect and do not execute when the Hyperlink column/text is clicked.  Is it possible to use the Hyperlink column for something other than a url?

3) I have used the Expression property of a textbox column to add the totals of other columns and this works.  However, I have set the FormatString to {0:C2} and it does not work.  The column is unformatted and does not show the $ sign or the comma in the number.  What am I doing wrong?

Thank you,
David A.

1 Answer, 1 is accepted

Sort by
0
Accepted
George
Telerik team
answered on 10 Oct 2013, 06:29 AM
Hello David,

Thank you for writing.

I can confirm that the TextAlignment property of the GridViewHyperlinkColumn does not work with previous version, however It is working correctly in the latest release - 2013 Q2 724. I would recommend you upgrade to the latest version. You can find the issue in our Public Issue Tracking System on the following url - http://www.telerik.com/support/pits.aspx#/details/Issue=12023.

With the latest version the HyperlinkOpening event is being fired, but the HyperlinkOpened is not because the hyperlink is not in a valid format. Moreover the hyperlink column is created for links and if you want to achieve any additional functionality, such as opening a new form, you need to implement that functionality yourself. For this you can use the HyperlinkOpening or the CellClick event:
void grid_CellClick(object sender, GridViewCellEventArgs e)
{
    if (e.Column is GridViewHyperlinkColumn)
    {
        if ((this.grid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "form1"))
        {
            new Form1().Show();
        }
    }
}

Format string of this sort would not work if the underlying value of the cell is string. That is why you would need to either use a GridViewDecimalColumn which will format the value out-of-the-box or format the string on the CellFormatting event:
void grid_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ColumnInfo is GridViewTextBoxColumn)
    {
        double value;
        if (double.TryParse(e.CellElement.RowInfo.Cells[e.ColumnIndex].Value + " ", out value))
        {
            e.CellElement.Text = string.Format(e.CellElement.FormatString, value);
        }
    }
}

I hope this helps.

Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
David A.
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or