Always the first record is selected. Help

40 posts, 12 answers
  1. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 08 Dec 2010 Link to this post

    Hi,

    You can also use the UserDeletingRow event as below
    Private Sub RadGridView1_UserDeletingRow(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewRowCancelEventArgs) Handles RadGridView1.UserDeletingRow
        If MessageBox.Show("Are you sure you want to delete this row?", Me.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            MessageBox.Show(e.Rows(0).Index.ToString())
        Else
            e.Cancel = True
        End If
    End Sub

    Richard
  2. francis
    francis avatar
    21 posts
    Member since:
    Oct 2010

    Posted 08 Dec 2010 Link to this post

    Sorry Richard error even cause me, I say the same. I added an attached image of error.

    I hope you....
  3. UI for WinForms is Visual Studio 2017 Ready
  4. francis
    francis avatar
    21 posts
    Member since:
    Oct 2010

    Posted 08 Dec 2010 Link to this post

    Sorry Richard error even cause me, I say the same. I added an attached image of error.

    I hope you....
  5. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 08 Dec 2010 Link to this post

    Here you go Francis.

    It's because you are using an older version, but it is still best to use the UserDeletingRow and UserDeletedRow as above.
    Here is a sample

    Private Sub RadGridView1_ContextMenuOpening(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.ContextMenuOpeningEventArgs) Handles RadGridView1.ContextMenuOpening
        If TypeOf e.ContextMenuProvider Is GridDataCellElement AndAlso TypeOf Me.RadGridView1.CurrentRow Is GridViewDataRowInfo Then
            For i As Integer = 0 To e.ContextMenu.Items.Count - 1
                If Not String.Equals(e.ContextMenu.Items(i).Text, "Delete Row") Then
                    e.ContextMenu.Items(i).Visibility = Telerik.WinControls.ElementVisibility.Collapsed
                End If
            Next
        End If
    End Sub
    Private Sub RadGridView1_UserDeletingRow(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewRowCancelEventArgs) Handles RadGridView1.UserDeletingRow
        If MessageBox.Show("Are you sure you want to delete this row?", Me.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            MessageBox.Show("Deleting Row Index: " & e.Rows(0).Index.ToString())
        Else
            e.Cancel = True
        End If
    End Sub
    Private Sub RadGridView1_UserDeletedRow(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewRowEventArgs) Handles RadGridView1.UserDeletedRow
        MessageBox.Show("Deleted Row")
    End Sub

    Let me know if you have any more questions ot comments
    Richard
  6. francis
    francis avatar
    21 posts
    Member since:
    Oct 2010

    Posted 08 Dec 2010 Link to this post

    I understand perfectly. but my version does not have this event, "UserDeletingRow"  I sorry.

    Richard, all I want is to know the number of the row that the user either delete the row 0, row 1, row 2 or 3. 

    I think we're close to doing .... 

    thank you very much for your help. 
  7. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 08 Dec 2010 Link to this post

    Hi Francis,

    Apologies, I don't have these older versions to try out these things on, but could you try this then please. I think this will do it.

    Private m_Index As Integer
    Private Sub RadGridView1_ContextMenuOpening(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.ContextMenuOpeningEventArgs) Handles RadGridView1.ContextMenuOpening
        If TypeOf e.ContextMenuProvider Is GridDataCellElement AndAlso TypeOf Me.RadGridView1.CurrentRow Is GridViewDataRowInfo Then
            For i As Integer = 0 To e.ContextMenu.Items.Count - 1
                If Not String.Equals(e.ContextMenu.Items(i).Text, "Delete Row") Then
                    e.ContextMenu.Items(i).Visibility = Telerik.WinControls.ElementVisibility.Collapsed
                Else
                    m_Index = Me.RadGridView1.MasterGridViewTemplate.CurrentRow.Index
                    AddHandler e.ContextMenu.Items(i).Click, AddressOf DeleteRow_Clicked
                End If
            Next
        End If
    End Sub
    Private Sub DeleteRow_Clicked(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show("Deleted: " & m_Index.ToString())
    End Sub

    All the best
    Richard
  8. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 08 Dec 2010 Link to this post

    Hello again guys,

    Francis, you can use the RowsChanging event and check for remove action, like so:
    void radGridView1_RowsChanging(object sender, GridViewCollectionChangingEventArgs e)
    {
        if (e.Action == NotifyCollectionChangedAction.Remove)
        {
            var rowsToBeRemoved = e.NewItems;
        }
    }

    or again VB:
    Private Sub radGridView1_RowsChanging(sender As Object, e As GridViewCollectionChangingEventArgs)
        If e.Action = NotifyCollectionChangedAction.Remove Then
            Dim rowsToBeRemoved = e.NewItems
        End If
    End Sub
    because i still don't know the language of this thread...

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

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP

  9. francis
    francis avatar
    21 posts
    Member since:
    Oct 2010

    Posted 08 Dec 2010 Link to this post

    Hey guys thank you very much but I've been ... 

    use this code "Me.GvData.CurrentRow.Cells (0). Value" for the record and then know the number of the row of the grid. 


    thank you very much. it is advisable to publish this conversation to help others ... 
  10. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 08 Dec 2010 Link to this post

    Hi Francis,

    I thought you said you couldn't use CurrentRow? Anyway, I'm glad you have this working. Please remember to mark all helpful posts as answer so others find the solution too.

    Thanks
    Richard
  11. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 09 Dec 2010 Link to this post

    Hi francis, 

    Thank you for writing.

    The desired behavior can be achieved by setting the SelectedItem property of RadMultiColumnComboBox to null:
    radMultiColumnComboBox1.SelectedItem = null;

    I hope this information addresses your question. If there is anything else I can assist you with, do not hesitate to contact me.
     
    Sincerely yours,
    Stefan
    the Telerik team
    Get started with RadControls for WinForms with numerous videos and detailed documentation.
Back to Top
UI for WinForms is Visual Studio 2017 Ready