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

How to get RadGridview CommandCellClick x/y position

7 Answers 140 Views
GridView
This is a migrated thread and some comments may be shown as answers.
anu
Top achievements
Rank 1
anu asked on 28 Jan 2011, 05:35 PM
is there a way to get the X,Y coordinates of  Gridview CommandCellClick event?
I am trying to show a panel when clicked on the button and want to postion the new panel right below the command button clicked on the gridview.

Thanks in advance for any help.
Arc

7 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 29 Jan 2011, 12:18 AM
Hello anu,

I have tried this with just a panel, and realised that this would cause some issues. For exmaple, if you scroll the grid, then the panel would stay in the same place, it would be hidden if you click on a button at the bottom of the grid and so on. Taking this into account, I think it is best to use the Telerik RadContextMenu and dynamically add the panel to the context menu. This gets over these issues and the context menu will then render in the correct place, even placing the panel outside of the bounds of the form if required.
The only part that I haven't yet solved is that there is a RadScrollViewer that creates the look of a right border on the panel, however, this seems to be the most elegant solution I can think of at the moment.

Here is the full code: (Just a grid on a form)

Designer File:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form
  
    'Form overrides dispose to clean up the component list. 
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub
  
    'Required by the Windows Form Designer 
    Private components As System.ComponentModel.IContainer
  
    'NOTE: The following procedure is required by the Windows Form Designer 
    'It can be modified using the Windows Form Designer.   
    'Do not modify it using the code editor. 
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Dim SortDescriptor1 As Telerik.WinControls.Data.SortDescriptor = New Telerik.WinControls.Data.SortDescriptor()
        Me.RadGridView1 = New Telerik.WinControls.UI.RadGridView()
        CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'RadGridView1
        '
        Me.RadGridView1.BackColor = System.Drawing.SystemColors.Control
        Me.RadGridView1.Cursor = System.Windows.Forms.Cursors.Default
        Me.RadGridView1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.RadGridView1.Font = New System.Drawing.Font("Segoe UI", 8.25!)
        Me.RadGridView1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.RadGridView1.ImeMode = System.Windows.Forms.ImeMode.NoControl
        Me.RadGridView1.Location = New System.Drawing.Point(0, 0)
        '
        'RadGridView1
        '
        Me.RadGridView1.MasterTemplate.EnableAlternatingRowColor = True
        Me.RadGridView1.MasterTemplate.ShowRowHeaderColumn = False
        SortDescriptor1.Direction = System.ComponentModel.ListSortDirection.Descending
        SortDescriptor1.PropertyName = "DateStamp"
        Me.RadGridView1.MasterTemplate.SortDescriptors.AddRange(New Telerik.WinControls.Data.SortDescriptor() {SortDescriptor1})
        Me.RadGridView1.Name = "RadGridView1"
        Me.RadGridView1.Padding = New System.Windows.Forms.Padding(0, 0, 0, 1)
        Me.RadGridView1.RightToLeft = System.Windows.Forms.RightToLeft.No
        '
        '
        '
        Me.RadGridView1.RootElement.Padding = New System.Windows.Forms.Padding(0, 0, 0, 1)
        Me.RadGridView1.Size = New System.Drawing.Size(874, 443)
        Me.RadGridView1.TabIndex = 0
        Me.RadGridView1.Text = "RadGridView1"
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(874, 443)
        Me.Controls.Add(Me.RadGridView1)
        Me.Name = "Form1"
        Me.Text = "Form 1"
        CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
  
    End Sub
    Friend WithEvents RadGridView1 As Telerik.WinControls.UI.RadGridView
  
End Class

Form1.vb
Imports Telerik.WinControls.UI
Imports System.Text
Imports Telerik.WinControls.Data
Imports Telerik.WinControls.UI.Export
Imports System.ComponentModel
Imports Telerik.WinControls
  
Public Class Form1
  
    Public Sub New()
        InitializeComponent()
  
        RadGridView1.AutoSizeRows = False
        RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None
        RadGridView1.AutoGenerateColumns = True
        RadGridView1.SelectionMode = GridViewSelectionMode.FullRowSelect
  
        Dim myList As New BindingList(Of MyObject)
        For i As Integer = 0 To 20
            Dim item As New MyObject("Name " & i.ToString(), "A text description " & i.ToString(), i)
            myList.Add(item)
        Next
        Me.RadGridView1.DataSource = myList
  
        Me.RadGridView1.Columns.Add(New GridViewCommandColumn("Command", "Command"))
    End Sub
  
    ''' <summary>
    ''' Add an event handler on the command button of the command column to capture the mouse down
    ''' </summary>
    Private Sub RadGridView1_CellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
        If TypeOf e.CellElement Is GridCommandCellElement Then
            If e.CellElement.Tag Is Nothing Then
                AddHandler CType(e.CellElement, GridCommandCellElement).CommandButton.MouseDown, AddressOf Button_MouseDown
            End If
            e.CellElement.Tag = True
        End If
    End Sub
  
    ''' <summary>
    ''' Build a panel into a rad context menu
    ''' </summary>
    Private Sub Button_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
        If e.Button = MouseButtons.Left Then
            Dim menu As New RadContextMenu()
  
            Dim panel As New RadPanel()
            panel.Text = "This is my dynamic context menu panel"
            panel.TextAlignment = ContentAlignment.MiddleCenter
            panel.Size = New Size(400, 200)
  
            Dim item As New RadMenuItem()
            item.AutoSize = False
            item.BackColor = Color.Orange
            item.Size = panel.Size
            item.Alignment = ContentAlignment.MiddleCenter
            item.Children.Add(New RadHostItem(panel))
            menu.Items.Add(item)
            menu.Show(Control.MousePosition)
        Else
            MyBase.OnMouseDown(e)
        End If
    End Sub
  
End Class
  
Public Class MyObject
  
    Public Sub New(ByVal name As String, ByVal description As String, ByVal id As Integer)
        Me.Name = name
        Me.Description = description
        Me.Id = id
    End Sub
  
    Public Property Name As String
    Public Property Description As String
    Public Property Id As Integer
End Class

I have included a screenshot (attached)
If you have any questions, please let me know
Richard
0
anu
Top achievements
Rank 1
answered on 31 Jan 2011, 11:55 PM
Hi Richard,
Thanks a lot for the solution, i could make this working.

Thanks
Anu

0
Richard Slade
Top achievements
Rank 2
answered on 01 Feb 2011, 12:23 AM
You're welcome. Glad that this has helped you.
Regards,
Richard
0
Naresh
Top achievements
Rank 1
answered on 09 May 2011, 02:05 PM
Hi Richard,

I'm confusing with this vb code, can u please explain this using c sharp. I'm also facing the same problem to get the x/y coordinates of a selected row.

Actually my problem is,

I have a radgrid with a delete Imagebutton, when i click on delete button a panel should hide that row with corresponding height and width of that row and the panel should contain two buttons with confirmation message... I'm using a jquery function to display the panel as slidedown when i click on delete button. this is my code to slidedown that panel

<script type="text/javascript">
        $(function () {
            $("#Link1").click(function (evt) {
                evt.preventDefault();
                $('#panelText').slideToggle('slow');
            });
        });
         
    </script>

can u please tell me how to display the panel on the selected row... and how to call that jquery function
0
Richard Slade
Top achievements
Rank 2
answered on 09 May 2011, 02:24 PM
Hello,

Are you sure you are posting in the correct forum?
Regards,
Richard
0
Naresh
Top achievements
Rank 1
answered on 09 May 2011, 02:30 PM
Yeah, I'm sure..

I'm  using rad controls in my project. I have the problem what i have explained below. can u please help me

Thanks
0
Richard Slade
Top achievements
Rank 2
answered on 09 May 2011, 02:35 PM
Hello,

JQuery is a browser based markup. If your questions refers to RadControls for ASP.NET, please redirect your query to that forum, as the web experts live there
Thanks
Richard
Tags
GridView
Asked by
anu
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
anu
Top achievements
Rank 1
Naresh
Top achievements
Rank 1
Share this question
or