DatagridView loses current edit on Background update -
Here's my problem: I have a datagrid view for custom gates binary list. A background thread is continuously updating the value of these items. Udpates are displaying correctly, and everything is fine except for one thing - if you try to edit a different field, while the background-updating field Updating, this loses the registered value. Here is a code sample that reflects this behavior: (For a new form, drop a new DataGrid view :)
Using the system; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; Using System.Windows.Forms; Using System.Threading; Namespace WindowsFormsApplication2 {Public Partial Category Form 1: Form {Private Binding List & lt; Foo & gt; Flist; Personal thrud thrd; Private Binding Source B; Public Form 1 () {Initialization (); Flist = new binding list & lt; Foo & gt; New Foo () {a = 1, b = 1, c = 1}, new foo () {a = 1, b = 1, c = 1}, new foo () {a = 1, b = 1, C = 1}, new foo () {a = 1, b = 1, c = 1}}; B = new binding resource (); B.DataSource = flist; DataGridView1.DataSource = b; Thrd = new thread (new threadstart (updated proxy)); Thrd.Start (); } Private Zero update () {flist.ToList (). ForEach (f = & gt; f.c ++); } Private Zero updPRoc () {while (true) {this.BeginInvoke (new method Invoker (upd)); Thread.Sleep (1000); }}} Public class foo: INotifyPropertyChanged {Private int _c; Public int a {get; Set; } Public int b {get; Set; } Public at C {get {return _c;} set {_c = value; If (property has changed! = Null) by changing property (this, new Property Changeed Event Event ("C")); }} #region INotifyPropertyChanged Member Public Event PropertyChangedEventHandler PropertyChanged; #endregion}}
So, if you edit columns A or B, you will see that the column C update loses your entry.
Any thoughts were appreciated
I played a bit with your code It seems that whatever is happening is that as soon as you add a new line, a new "foo" object automatically bindilist
gets the data-grade functionality of the datagrid power Because it is valid as an object in the collection, so the 'C' parameter works by you Nvit grow by thread function and you will lose your input changes, since it will cause to refresh the 'Datagreedviyu' cause property Chenjedivent firing.
The suggestion I give is a different scene or form, where you enter new object information. Then, on the right, add a new Foo object to the list. This data grid eliminates the purpose of connecting lines directly to Viv and if you want you can argue with me, but you can do your legalization somewhere else. Do you want code for verification of all your verification inside and inside the UI code? Do you want a user to "need a number and there is no text!" Message while remaining datagrid views are being updated? May be a bit disappointing.
In addition to this, if the data is to be changed continuously, there is little to be done to make Editable from Gridview. You want to have a connect-oriented pattern for the data source, some of which constantly change. You want to reconsider how you are displaying this information and probably looks at user data and in a different way Can edit
My 5 cents anyway.
Wish you Yoni, it was fun to see that the numbers get mad and I understand your problem.
Leo Bharatiya
Comments
Post a Comment