I must be going crazy. Scroll down to the bottom object, then select any object, the listbox will always scroll up so the selected item is at the bottom of the visible list. Occurs on the CancelEdit.
using System; using System.Windows.Forms; using Csla; using Csla.Core; namespace WindowsFormsApplication1 { public partial class Form1: Form { public Form1() { InitializeComponent(); } BusinessBase _currentItem = null; BindingSource _bindingSource = new BindingSource(); People people = new People(); private void Form1_Load(object sender, EventArgs e) { Height = 400; Width = 600; ListBox listbox1 = new ListBox(); listbox1.Width = 500; listbox1.Height = 300; listbox1.Top = 50; listbox1.Left = 50; Controls.Add(listbox1); for ( int i = 0; i < 50; i++ ) { Person person = new Person(); person.Name = "Test" + i.ToString(); people.Add(person); } _bindingSource.CurrentChanged += new EventHandler(bs_CurrentChanged); _bindingSource.DataSource = people; listbox1.DataSource = _bindingSource; } void bs_CurrentChanged(object sender, EventArgs e) { if ( _currentItem != null ) _currentItem.CancelEdit(); _currentItem = (BusinessBase) _bindingSource.Current; _currentItem.BeginEdit(); } } public class People: BusinessListBase { } public class Person: BusinessBase { private string _name; public string Name { get { return _name; } set { _name = value; } } public override string ToString() { return _name; } } }
Is anyone using BeginEdit without attaching it to an "Edit" button? My thought process is that if the position is changing on the BindingSource (CurrentChanged), to Cancel any edits if not dirty (and if dirty I have a popup in my real code) on the original current item, and do a BeginEdit on the new current item. So far my users hate hitting and edit button and automatically. The new process works but for whatever reason the listbox selection changes and I'm not sure why.
I use BeginEdit without edit button. I think, you will
need to unbind and rebind your controls. On a few occasions I added code
to Cancel to remember what item was highlighted and then selected the same item
after cancel and re-bind (if available – it could have been new item)
Sergey Barskiy
Senior Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: ErikPhilips
[mailto:cslanet@lhotka.net]
Sent: Monday, April 14, 2008 2:28 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] CancelEdit causes Listbox scrolling?
Is anyone using BeginEdit without attaching it to an "Edit"
button? My thought process is that if the position is changing on the
BindingSource (CurrentChanged), to Cancel any edits if not dirty (and if
dirty I have a popup in my real code) on the original current item, and do a
BeginEdit on the new current item. So far my users hate hitting and edit
button and automatically. The new process works but for whatever reason the
listbox selection changes and I'm not sure why.
That's a fantastic solution as far as I can see. I went through all the events of the listbox but apparently wasn't thorough enough. Thanks a lot!
Copyright (c) Marimer LLC