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

Stop selected row change on new row added

1 Answer 253 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jason Parrish
Top achievements
Rank 1
Jason Parrish asked on 04 Nov 2011, 06:30 PM
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

1 Answer, 1 is accepted

Sort by
1
Accepted
Jason Parrish
Top achievements
Rank 1
answered on 04 Nov 2011, 07:23 PM
Found the needed property!

RadGridView1.MasterTemplate.SelectLastAddedRow = False
Tags
GridView
Asked by
Jason Parrish
Top achievements
Rank 1
Answers by
Jason Parrish
Top achievements
Rank 1
Share this question
or