Rad Grid CellDoubleClick event

24 posts, 1 answers
  1. Bob
    Bob avatar
    14 posts
    Member since:
    Nov 2010

    Posted 03 Dec 2010 Link to this post

    I am trying to write some code for the cellDoubleClick event, but it seems that it only fires if the cells column is readonly.  Is there a way around this?  It looks like the first click will open the cell up for editing and the second click is ignored.  I want to have different code run for a single click  or a double click event.
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 04 Dec 2010 Link to this post

    Hi Bob,

    This happens because when you click a cell that is not read only as you rightly said it goes into edit mode. You are then no longer clicking on the cell you are clicking on the textbox editor so the click event is being handled there instead.

    What is the goal you are trying to get to, and perhaps I can help find a suitable way around it for you.
    Thanks
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 04 Dec 2010 Link to this post

    Hello Bob,

    Even if the grid is editable, you can double click on the cell and raise the CellDoubleClick event, please take a look at the following example:
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
     
    public partial class Form1 : Form
    {
        private RadGridView radGridView1;
     
        private RadTextBox radTextBox1;
     
        public Form1()
        {
            InitializeComponent();
            this.Size = new Size(600, 600);
            this.Controls.Add(radGridView1 = new RadGridView());
            radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            radGridView1.Dock = DockStyle.Fill;
     
            this.Controls.Add(radTextBox1 = new RadTextBox());
            radTextBox1.Dock = DockStyle.Bottom;
            radTextBox1.Multiline = true;
            radTextBox1.MinimumSize = new Size(0, 200);
            radTextBox1.Clear();
            radTextBox1.AutoScroll = true;
            radGridView1.CellClick += new GridViewCellEventHandler(radGridView1_CellClick);
            radGridView1.CellDoubleClick += new GridViewCellEventHandler(radGridView1_CellDoubleClick);
        }
     
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            radGridView1.DataSource = new TestsCollection();
        }
     
        void radGridView1_CellDoubleClick(object sender, GridViewCellEventArgs e)
        {
            radTextBox1.Text += DateTime.Now.ToString() + ": CellDoubleClick called" + Environment.NewLine;
        }
     
        void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
        {
            radTextBox1.Text += DateTime.Now.ToString() + ": CellClick called" + Environment.NewLine;
        }
    }
     
    public class Test
    {
        public int Id
        {
            get;
            set;
        }
     
        public string Name
        {
            get;
            set;
        }
     
        public Test(int id, string name)
        {
            this.Id = id;
            this.Name = name;
        }
    }
     
    public class TestsCollection : BindingList<Test>
    {
        public TestsCollection()
        {
            for (int i = 0; i < 10; i++)
            {
                this.Add(new Test(i, "Name" + i));
            }
        }
    }

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 04 Dec 2010 Link to this post

    Hi Emanuel,

    I don't beleive that this will be the case,. Can you try the following:
    • Launch the program
    • Double click on a cell
    • the cell click event and double click event are raised and the cell is put into edit mode
    • Double click on another cell, neither event is raised
    • Click on a header to end edit
    • The cell click is raised
    • Double click on a cell, both events are raised, cell is in edit
    • Double click on another cell, no events are raised

    Bob, let me know your goal and I will do my best to help
    Thanks
    Richard

  6. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 04 Dec 2010 Link to this post

    Hello Richard,

    That's why i added the textbox there, so you can see exactly what happens and when.

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  7. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 04 Dec 2010 Link to this post

    Hi Emanuel,

    But that's exactly my point. Bob has mentioned he would like to perform different actions on CellClick than CellDoubleClick.
    Richard
  8. Bob
    Bob avatar
    14 posts
    Member since:
    Nov 2010

    Posted 06 Dec 2010 Link to this post

    Here is exactly what I am trying to do.  I have a datagrid that our users enter data on.  If the user double clicks on a cell, todays date is automatically entered.  If they single click on it, they can type in the cell as needed (maybe to enter a different date).  This worked when we were using the standard .Net datagrid, but the Telerik grid will not allow this since the double click event will not fire if the cell is not readonly.  If I set readonly to false, the first click on the cell opens it up for editing and the second click is ignored. 

    Can I bind an event to the textbox editor of the cell?
  9. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 06 Dec 2010 Link to this post

    Hello Bob,

    Thanks for writing back. As you are using Dates in your RadgridView, I'd suggest you use a GridViewDateTimeColumn, rather than a GridViewTextBoxColumn which from your description I think you are currently using. With a GridViewDateTimeColumn you are able to set a NullValue so if any of your data does not have a Date value set then the grid will automatically set the date value to be the null value.

    This will also do away with the Single Click / Double Click scenario and allow users to pick the date they wish and still pick a date from a calendar.

    this link details more information on the GridViewDateTimeColumn

    And here is a sample that shows the first row has an automatic date of today, even though the data for that cell is null.

    Imports Telerik.WinControls.UI
    Imports System.ComponentModel
      
    Public Class Form1
      
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      
            Me.RadGridView1.MultiSelect = True
            Me.RadGridView1.AllowRowResize = False
            Me.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
            Me.RadGridView1.AutoGenerateColumns = False
            Me.RadGridView1.AllowAddNewRow = True
      
            Dim nameColumn As New GridViewTextBoxColumn("Name")
            Dim dateChangedColumn As New GridViewDateTimeColumn("DateChanged")
      
            dateChangedColumn.NullValue = New DateTime(Now.Year, Now.Month, Now.Day)
            dateChangedColumn.FormatString = "{0:dd/MM/yyyy}"
      
      
            Me.RadGridView1.Columns.Add(nameColumn)
            Me.RadGridView1.Columns.Add(dateChangedColumn)
      
            Dim rowInfo As GridViewRowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "Richard"
            rowInfo.Cells(1).Value = Nothing ' Will be set to default value (today)
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "Bob"
            rowInfo.Cells(1).Value = Now
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "Ian"
            rowInfo.Cells(1).Value = Now.AddDays(1)
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "Fred"
            rowInfo.Cells(1).Value = Now.AddDays(4)
      
      
        End Sub
    End Class

    hope that helps, but just let me know if you have any further questions, and I'll do my best
    to help
    Thanks
    Richard
  10. Bob
    Bob avatar
    14 posts
    Member since:
    Nov 2010

    Posted 06 Dec 2010 Link to this post

    OK.  So the bottom line is that I cannot get the double click event to fire unless the cell is readonly.  They don't want to use the date picker because it takes too long.  They just want to double click and have the date populate.  I will have to come up with something else.
  11. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 06 Dec 2010 Link to this post

    Hi Bob,

    In that case, I will look into an alternative solution for you if you have to use a GridViewTextBoxColumn. I will get back to you as soon as possible.

    All the best
    Richard
  12. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 06 Dec 2010 Link to this post

    Hi Bob,

    I don't think this is quite right yet, and it's not the cleanest solution, but have a go with this. It does seem to work if you double click on a cell it enters the date, and single clicking on a cell puts it just into edit mode. It's just a grid on a form.

    Imports Telerik.WinControls.UI
    Imports System.ComponentModel
      
    Public Class Form1
      
        Private WithEvents m_BackgroundWorker As New BackgroundWorker()
        Private m_DateChangedColumn As GridViewTextBoxColumn
      
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      
            Me.RadGridView1.MultiSelect = True
            Me.RadGridView1.AllowRowResize = False
            Me.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
            Me.RadGridView1.AutoGenerateColumns = False
            Me.RadGridView1.AllowAddNewRow = True
      
            Dim nameColumn As New GridViewTextBoxColumn("Name")
            m_DateChangedColumn = New GridViewTextBoxColumn("DateChanged")
      
            m_DateChangedColumn.FormatString = "{0:dd/MM/yyyy}"
            m_DateChangedColumn.ReadOnly = True
      
            Me.RadGridView1.Columns.Add(nameColumn)
            Me.RadGridView1.Columns.Add(m_DateChangedColumn)
      
            Dim rowInfo As GridViewRowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "Richard"
            rowInfo.Cells(1).Value = Nothing
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "Bob"
            rowInfo.Cells(1).Value = Nothing
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "Ian"
            rowInfo.Cells(1).Value = Now.AddDays(1)
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "Fred"
            rowInfo.Cells(1).Value = Now.AddDays(4)
      
            AddHandler m_BackgroundWorker.RunWorkerCompleted, AddressOf BackgroundWorker_RunworkCompleted
        End Sub
      
        Private Sub BackgroundWorker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles m_BackgroundWorker.DoWork
            Threading.Thread.Sleep(300)
        End Sub
      
        Private Sub BackgroundWorker_RunworkCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
            If Me.RadGridView1.CurrentCell.ColumnInfo.Name = "DateChanged" Then
                m_DateChangedColumn.ReadOnly = False
                Me.RadGridView1.CurrentCell.RowInfo.Cells("DateChanged").BeginEdit()
            End If
        End Sub
      
        Private Sub RadGridView1_CellClick(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellClick
            If Me.RadGridView1.CurrentCell.ColumnInfo.Name = "DateChanged" Then
      
                m_BackgroundWorker.RunWorkerAsync()
            End If
        End Sub
      
        Private Sub RadGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellDoubleClick
            If Me.RadGridView1.CurrentCell.ColumnInfo.Name = "DateChanged" Then
      
                m_DateChangedColumn.ReadOnly = False
                If e.Row.Cells("DateChanged").Value Is Nothing Then
                    e.Row.Cells("DateChanged").Value = Now.ToString()
                End If
                e.Row.Cells("DateChanged").BeginEdit()
            End If
        End Sub
      
        Private Sub RadGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellEndEdit
            m_DateChangedColumn.ReadOnly = True
        End Sub
      
    End Class

    Hope this helps, but let me know if you need any more information
    Richard
  13. Bob
    Bob avatar
    14 posts
    Member since:
    Nov 2010

    Posted 07 Dec 2010 Link to this post

    Thanks.  This does exactly what I need it to do.  I know it is a little unconventional, but my users will be very happy.

    Thanks again

    Bob
  14. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Dec 2010 Link to this post

    You're welcome Bob. Pleased to help. Please remember to mark as answer so others can find the solution too. 
    All the best
    Richard
  15. Brad
    Brad avatar
    20 posts
    Member since:
    Apr 2010

    Posted 03 Nov 2011 Link to this post

    Hi Bob, Richard and Emanuel Varga 

    My clients need to double click and open a reference form as they are editing values in a grid. So, I worked through handling CellDoubleClick when Rad GridView is not in Read Only mode by combining your examples and the one I found in this thread: RadTextBoxEditor Doubleclick not firing

    To do it I add a generic double click event handler to the Cell Editor base control in the Cell Begin Edit event. The generic event calls the Cell Double Click event to mimic double clicks in Read Only mode. The code can handle Text and ComboBox columns, support for other columns was not required in my project.

    My example and project uses RadControls v.2011.1.11.419 

    public partial class Form1 : Form
    {
        private RadGridView radGridView1;
        private RadTextBox radTextBox1;
     
        bool isTextEditorSetup;
        bool isComboBoxEditorSetup;
     
        public Form1()
        {
            InitializeComponent();
     
            this.Size = new Size(600, 600);
            this.Controls.Add(radGridView1 = new RadGridView());
            radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            radGridView1.Dock = DockStyle.Fill;
     
            radGridView1.ReadOnly = false;
     
            this.Controls.Add(radTextBox1 = new RadTextBox());
            radTextBox1.Dock = DockStyle.Bottom;
            radTextBox1.Multiline = true;
            radTextBox1.MinimumSize = new Size(0, 200);
            radTextBox1.Clear();
            radTextBox1.AutoScroll = true;
            radGridView1.CellBeginEdit += new GridViewCellCancelEventHandler(radGridView1_CellBeginEdit);
            radGridView1.CellDoubleClick += new GridViewCellEventHandler(radGridView1_CellDoubleClick);           
        }
     
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            radGridView1.DataSource = new TestsCollection();
        }      
     
        private void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
        {
            if (!isComboBoxEditorSetup && e.Column is GridViewComboBoxColumn)
            {
                //This Event Handler applies to columns of type GridViewComboBoxColumn
                ((e.ActiveEditor as RadDropDownListEditor).EditorElement as RadDropDownListEditorElement).DoubleClick += new EventHandler(editor_DoubleClick);
                isComboBoxEditorSetup = true;  
            }
            if (!isTextEditorSetup && e.Column is GridViewTextBoxColumn)
            {
                //This Event Handler applies to columns of type GridViewTextBoxColumn
                ((e.ActiveEditor as RadTextBoxEditor).EditorElement as RadTextBoxEditorElement).TextBoxItem.HostedControl.DoubleClick += new EventHandler(editor_DoubleClick);
                isTextEditorSetup = true;
            }  
        }
     
        private void editor_DoubleClick(object sender, EventArgs e)
        {
            radTextBox1.Text += DateTime.Now.ToString() + ": Form1_DoubleClick called" + Environment.NewLine;
            //Construct Arguments for CellDoubleClick
            GridViewCellEventArgs arg = new GridViewCellEventArgs(this.radGridView1.CurrentRow, this.radGridView1.CurrentColumn, this.radGridView1.ActiveEditor);
            radGridView1_CellDoubleClick(sender, arg);
        }
     
        private void radGridView1_CellDoubleClick(object sender, GridViewCellEventArgs e)
        {
            //return without doing anything if new row or one of the required double click cells is NULL.
            if (e.RowIndex == -1 || e.Row.Cells["Name"].Value == null || e.Row.Cells["Name"].Value == DBNull.Value)
                return;
     
            radTextBox1.Text += DateTime.Now.ToString() + ": radGridView1_CellDoubleClick called: " + e.Row.Cells["Name"].Value + Environment.NewLine;
        }  
     
    }
     
    public class Test
    {
        public int Id
        {
            get;
            set;
        }
     
        public string Name
        {
            get;
            set;
        }
     
        public Test(int id, string name)
        {
            this.Id = id;
            this.Name = name;
        }
    }
     
    public class TestsCollection : BindingList<Test>
    {
        public TestsCollection()
        {
            for (int i = 0; i < 10; i++)
            {
                this.Add(new Test(i, "Name" + i));
            }
        }
    }
  16. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 08 Nov 2011 Link to this post

    Hello Brad,

    Thank you for sharing your code and sending us the sample project. For the convenience of the customers, who will find your solution useful, I am adding a link to your the code library thread:
    Cell Double Click when ReadOnly = false, for Text and ComboBox Columns

    Let me know if you have any other questions.

    Kind regards,
    Martin Vasilev
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  17. Hrishikesh
    Hrishikesh avatar
    6 posts
    Member since:
    Dec 2015

    Posted 21 Dec 2015 Link to this post

    How to Display record RadGridView Row Double Click and display to Rad text box?

    see attached file

  18. Hrishikesh
    Hrishikesh avatar
    6 posts
    Member since:
    Dec 2015

    Posted 21 Dec 2015 in reply to Hrishikesh Link to this post

    How to Display record RadGridView Row Double Click and display to Rad text box?  which use code in vb.net 2010
  19. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 22 Dec 2015 Link to this post

    Hi Hrishikesh,

    Let me start by mentioning that this forum concerns Telerik UI for WinForms and I will address your question for this product.

    What you can do is to place RadGridView and RadDataLayout on a Form. Then you can subscribe to the CellDoubleClick event of RadGridView, and in the handler set the DataSource for RadDataLayout and it will automatically populate itself with the needed editors according to the row's fields:
    Private Sub radGridView1_CellDoubleClick(sender As Object, e As GridViewCellEventArgs)
        dataLayout.DataSource = e.Row.DataBoundItem
    End Sub

    Alternatively, instead of using the double click event, you can use CurrentRowChanged, and this way, every time the user changes the current row, the data layout control will be updated.

    I hope this helps.

    Regards,
    Stefan
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  20. Hrishikesh
    Hrishikesh avatar
    6 posts
    Member since:
    Dec 2015

    Posted 28 Dec 2015 in reply to Stefan Link to this post

    Sir

    Please send sample project

    Thanks for the support

  21. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 28 Dec 2015 Link to this post

    Hello Hrishikesh,

    Thank you for writing back.

    By default, double-clicking over a cell will activate the editor. When the editor is active and you double click on another cell, the first click will activate the editor for the new cell and the second click will be over the editor itself. Hence, you can either cancel the RadGridViewView.CellBeginEdit event or set the  BeginEditMode property to RadGridViewBeginEditMode.BeginEditProgrammatically.

    While working on this thread, I have encountered a rendering issue in RadDataLayout

    I have logged it in our feedback portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item.

    Currently, the possible solution that I can suggest is to use RadDataEntry instead of RadDataLayout. You can find attached a sample project. 

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  22. Hrishikesh
    Hrishikesh avatar
    6 posts
    Member since:
    Dec 2015

    Posted 29 Dec 2015 in reply to Dess Link to this post

    Sir,

    I am not using c#, I am using vb code. Pls send vb coded project...!

    example is

    Private Sub RadGridView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

    RadGridView1.DoubleClick
            txtID = RadGridView1.CurrentRow.Cells(0).Value
            txtCustName = RadGridView1.CurrentRow.Cells(1).Value
            txtAddress = RadGridView1.CurrentRow.Cells(2).Value
            txtContact = RadGridView1.CurrentRow.Cells(3).Value
        End Sub

     Pls see attached screenshot....!

     

  23. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 30 Dec 2015 Link to this post

    Hello Hrishikesh,

    Thank you for writing back.

    You can find attached a sample project in VB.NET.

    Feel free to use our online code converter in future which converts from C# to VB and from VB to C#.

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  24. Hrishikesh
    Hrishikesh avatar
    6 posts
    Member since:
    Dec 2015

    Posted 30 Dec 2015 in reply to Dess Link to this post

    How add image row header button ?

    and how to use header button?

    pls attach sample in vb.net

    see attached screen shot...!

  25. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 04 Jan Link to this post

    Hello Hrishikesh,

    Thank you for writing back. 

    By default, GridRowHeaderCellElements are used to indicate the current row in a RadGridView with a specific arrow image. You can use the ViewCellFormatting event and apply the desired image to the GridRowHeaderCellElement. You can find a sample demonstrating how to use the ViewCellFormatting in the following link: http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html

    I hope this information helps. If you have any additional questions, please let me know.
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready