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

CellClick event only when click on text

3 Answers 675 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Elad
Top achievements
Rank 1
Elad asked on 09 Oct 2012, 11:18 AM
Hi,

I'm the same user from ticket
610565

.

I decided to use RadGridView instead of RadListView because it's performance is much better....
I use the grid with only one column - which includes simple text but also links, but without the HyperlinkColumn (I must have only one column so the control will look like a list of messages).

I also registered for the cellClick event:
private void radGridView1_CellClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
    {
      GridViewCellInfo cell = (GridViewCellInfo)radGridView.Rows[e.RowIndex].Cells[e.ColumnIndex];
  
      if (cell.Tag != null)
      {
        Process.Start(cell.Tag.ToString());
      }
    }

The question is how can I start the link open process ONLY when the user click on the TEXT, and not anywhere in the specific cell.

Thanks,
Hila.

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Todorov
Telerik team
answered on 10 Oct 2012, 03:48 PM
Hello Hila,

If you are using the default cell elements, there is no way to determine if the click was over the text. To achieve this, you will need to create a custom cell element with a single child element to hold its text. This way you will be able to access the ControlBoundingRectangle property of the inner element and perform a hit test.

As an alternative, you can use the HTML-like formatting capabilities of our elements, especially the <a> tag to place links inside your cells' text.

I am enclosing a sample project which demonstrates the both scenarios. I hope you find it useful.

Do not hesitate to ask if you have any additional questions.

Greetings,
Ivan Todorov
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Elad
Top achievements
Rank 1
answered on 11 Oct 2012, 07:48 AM
Hi Ivan,

Thanks for the answer, the first solution was great for me (the second not because the link is not working on Directory/File path cases).
Another question almost in the same area-
Is there a way to select (highlight) the text INSIDE a GeidView cell, without let the user edit the row.
I know the user can copy the cell/row- already implemented this, but I want to let the user select only a part of the text in the cell, for example- if the cell contains a long path to file and the user would like to select only part of it.

I've tried to do it with the Begin/EndEdit but I don't want to save the changes (if the user do some changes in the text..) but when I "e.Cancel" it inside CellValidating the edit mode get stuck and each other row I'm clicking on causing it to open in edit mode....
By the way- I'm not saving a DataSource for all the messages that are displayed on the gridView. (And not interested to do so).

Do you have any solution for this?

Thanks,
Hila.
0
Ivan Todorov
Telerik team
answered on 15 Oct 2012, 12:49 PM
Hello Hila,

You can implement a custom editor which is read-only. This way the editor will open and let the user select some text but will not allow editing the original value. I am sending you the previous sample project with some modifications in Form1 to demonstrate how you can achieve this.

Hope this will help you. Feel free to ask if you have any additional questions.

Regards,
Ivan Todorov
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
Tags
GridView
Asked by
Elad
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Elad
Top achievements
Rank 1
Share this question
or