Re: Problem mit BindingSource
- From: "Elmar Boye" <ElmarB@xxxxxxx>
- Date: Mon, 15 May 2006 11:11:57 +0200
Hallo Peter,
Peter Fleischer <peter.fleischer_nospam_@xxxxxx> schrieb ...
Jens Winter wrote:
So sieht meine Implementierung des IEditableObject-Interfaces aus....
Kannst du bestätigen, dass meine Umsetzung in Ordnung ist?
Ich habe das Szenario mal nach gestellt und es funktioniert bei mir
nicht.
Public Class Form36
[...]
ist in einigen Belangen unzureichend...
Private Sub Form36_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim al As New ArrayList
ArrayList implementiert kein ListChanged somit funktioniert
die Benachrichtigung eines Positionswechsels nicht.
Da Jens mit .NET 2.0 arbeitet wäre BindingList<T> sinnvoller.
Private Class clsObj
Implements System.ComponentModel.IEditableObject
sollte in .NET 2.0 INotfiyPropertyChanged implementieren,
dann klappt die Benachrichtigung auch über mehrere Steuerelemente.
Bei .NET 1.x wären da noch jeweils einzelne PropertyChanged Ereignisse
erforderlich gewesen.
Eine korrigierte Umsetzung - Jens zuliebe in C# und Verzicht auf Clone
etc. ums direkter sichtbar zu machen:
/// Vereinfachte MeinDTO Klasse
using System;
using System.ComponentModel;
using System.Diagnostics;
namespace WindowsApplication1
{
public class MeinDTO :
System.ComponentModel.IEditableObject,
System.ComponentModel.INotifyPropertyChanged
{
private MeinDTO _backup;
private int _id;
private string _name;
public MeinDTO() { }
public MeinDTO(int id, string name)
{
this._id = id;
this._name = name;
}
public int Id
{
get { return this._id; }
set
{
if (this._id != value)
{
BeginEdit();
this._id = value;
OnPropertyChanged("Id");
}
}
}
public string Name
{
get { return this._name; }
set
{
if (this._name != value)
{
BeginEdit();
this._name = value;
OnPropertyChanged("Name");
}
}
}
protected virtual void OnPropertyChanged(string propertyName)
{
Debug.WriteLine(String.Format("PropertyChanged: {0}",
propertyName), "MeinDTO");
if (this.PropertyChanged != null)
this.PropertyChanged(this, new
System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
public event System.ComponentModel.PropertyChangedEventHandler
PropertyChanged;
public void BeginEdit()
{
if (_backup == null)
{
Debug.WriteLine("BeginEdit", "MeinDTO");
_backup = new MeinDTO(this._id, this._name);
}
}
public void EndEdit()
{
if (_backup != null)
{
Debug.WriteLine("EndEdit", "MeinDTO");
_backup = null;
}
}
public void CancelEdit()
{
if (_backup != null)
{
Debug.WriteLine("CancelEdit", "MeinDTO");
this._id = _backup._id;
this._name = _backup._name;
_backup = null;
OnPropertyChanged(null);
}
}
}
}
\\\
/// Formular mit 2 TextBoxen und DataGrid:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class DTOForm : Form
{
public DTOForm()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
BindingList<MeinDTO> list = new BindingList<MeinDTO>();
list.Add(new MeinDTO(4711, "Name 4711"));
list.Add(new MeinDTO(4712, "Name 4712"));
list.Add(new MeinDTO(4713, "Name 4713"));
this.dataGrid1.SetDataBinding(list, "");
this.textBox1.DataBindings.Add(new Binding("Text", list, "Id"));
this.textBox2.DataBindings.Add(new Binding("Text", list,
"Name"));
}
}
}
\\\
.
- Follow-Ups:
- Re: Problem mit BindingSource
- From: Peter Fleischer
- Re: Problem mit BindingSource
- References:
- Problem mit BindingSource
- From: Jens Winter
- Re: Problem mit BindingSource
- From: Peter Fleischer
- Re: Problem mit BindingSource
- From: Jens Winter
- Re: Problem mit BindingSource
- From: Peter Fleischer
- Re: Problem mit BindingSource
- From: Jens Winter
- Re: Problem mit BindingSource
- From: Peter Fleischer
- Re: Problem mit BindingSource
- From: Jens Winter
- Re: Problem mit BindingSource
- From: Peter Fleischer
- Re: Problem mit BindingSource
- From: Jens Winter
- Re: Problem mit BindingSource
- From: Peter Fleischer
- Problem mit BindingSource
- Prev by Date: Re: Datenfelder spaces und SQL-Server 2005
- Next by Date: Re: Problem mit BindingSource
- Previous by thread: Re: Problem mit BindingSource
- Next by thread: Re: Problem mit BindingSource
- Index(es):
Relevant Pages
|