Stop selected row change on new row added

2 posts, 1 answers
  1. Jason Parrish
    Jason Parrish avatar
    87 posts
    Member since:
    Sep 2009

    Posted 04 Nov 2011 Link to this post

    Is there a way (ideally a property) to stop the grid from automatically selecting the newest row when one is added to the datasource?  

    See the example below.  When an item is added to the bindinglist, I want to prevent the row selection from occuring.  I know I can set a variable before adding the item, and then cancel the row change on the "changing" event.  But ideally, I could just turn off the functionality.

    It also needs to NOT automatically scroll to it.

    Thoughts?

    Please note:  This behavior does NOT occur on the MS datagrid.

    Imports System.ComponentModel
     
    Public Class Form1
     
        Private myList As BindingList(Of MyObject)
     
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
            myList = New BindingList(Of MyObject)()
            myList.Add(New MyObject(1, "Outdoor"))
            myList.Add(New MyObject(2, "Hardware"))
            myList.Add(New MyObject(3, "Tools"))
            myList.Add(New MyObject(4, "Books"))
            myList.Add(New MyObject(5, "Appliances"))
            AddHandler myList.ListChanged, AddressOf myList_ListChanged
            RadGridView1.DataSource = myList
        End Sub
        Sub myList_ListChanged(ByVal sender As Object, ByVal e As ListChangedEventArgs)
     
        End Sub
        Private Sub RadButton1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
            myList.Add(New MyObject(6, "Plants"))
            ' DO NOT CHANGE SELECTION!
        End Sub
     
     
     
        Public Class MyObject
            Public Sub New(ByVal myInt As Integer, ByVal myString As String)
                _myInt = myInt
                _myString = myString
            End Sub
            Private _myInt As Integer
            Public Property MyInt() As Integer
                Get
                    Return _myInt
                End Get
                Set(ByVal value As Integer)
                    _myInt = value
                End Set
            End Property
            Private _myString As String
            Public Property MyString() As String
                Get
                    Return _myString
                End Get
                Set(ByVal value As String)
                    _myString = value
                End Set
            End Property
        End Class
     
    End Class
  2. Answer
    Jason Parrish
    Jason Parrish avatar
    87 posts
    Member since:
    Sep 2009

    Posted 04 Nov 2011 Link to this post

    Found the needed property!

    RadGridView1.MasterTemplate.SelectLastAddedRow = False
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top