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

Cancel Row selection after handling HyperlinkOpening

1 Answer 62 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 1
Keith asked on 07 May 2016, 12:27 AM

Hello Support,

  I have two Gridviews, when an item on the top grid is selected, the bottom grid populates with content related to the selection that is displayed by handling the SelectionChanged() event.  I grid also includes GridViewHyperlinkColumn()s which show a popup window by handling the HyperlinkOpening() event.

Currently, when I click on a hyperlink on a row that is not selected, my dialog opens up.  When I close the dialog the row is selected is the bottom content opens up.

The behavior I would like is that when I click a hyperlink, the row is not selected.  Or, when clicking the hyperlink, the row is selected, then the hyperlinkOpening() is handled.

What is the recommended way to accomplish this?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 09 May 2016, 01:49 PM
Hi Keith,

Thank you for writing.

RadGridView exposes several data validation events and the RowValidating event is suitable to be handled in your type of scenario: Data Validation.

In order to achieve your task, you would need to cancel the RowValidating every time you open your dialog int the HyperlinkOpening event you are already handling. Please check my code snippet below: 
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
 
        GridViewDecimalColumn decColumn = new GridViewDecimalColumn("Row");
        this.radGridView1.Columns.Add(decColumn);
 
        GridViewHyperlinkColumn column = new GridViewHyperlinkColumn("Hyperlink column");
        column.HyperlinkOpenArea = HyperlinkOpenArea.Cell;
 
        this.radGridView1.Columns.Add(column);
 
        this.radGridView1.Rows.Add(1, "Show Popup");
        this.radGridView1.Rows.Add(2, "Show Popup");
        this.radGridView1.Rows.Add(3, "Show Popup");
        this.radGridView1.Rows.Add(4, "Show Popup");
        this.radGridView1.Rows.Add(5, "Show Popup");
        this.radGridView1.Rows.Add(6, "Show Popup");
        this.radGridView1.Rows.Add(7, "Show Popup");
 
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
 
        this.radGridView1.RowValidating += radGridView1_RowValidating;
        this.radGridView1.HyperlinkOpening += radGridView1_HyperlinkOpening;
    }
 
    private void radGridView1_RowValidating(object sender, RowValidatingEventArgs e)
    {
        if (cancelRowSelection)
        {
            e.Cancel = true;
        }
 
        cancelRowSelection = false;
    }
 
    bool cancelRowSelection = false;
    private void radGridView1_HyperlinkOpening(object sender, HyperlinkOpeningEventArgs e)
    {
        Form dialog = new Form() { Text = "Dialog" };
        dialog.ShowDialog();
        cancelRowSelection = true;
    }
}

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Keith
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or