Groups | Blog | Home
all groups > dotnet windows forms databinding > june 2006 >

dotnet windows forms databinding : Refresh DataView / DataGridView...! Hope somebody can help!


rancidpunx NO[at]SPAM gmx.at
6/14/2006 2:01:11 AM
Hi!

First of all, i know that this topic is discussed very often in this
newsgroup, but i can't find an answer to my question.

I try to describe my problem as good as possible (I'm using C#):

I have a DataBase-Class with DataSets and DataViews.
2 other classes (i call them class A and class B) make an object of my
database-class.

Class A inserts / deletes rows in one of my DataSets in the DataBase
class.
In Class B, one DataGridView is connected to a DataView form the
DataBase class.

All data is displayed correctly, but if my class A edits the DataView
the dataGridView in Class B doesn't refresh the changes!!

So what can i do??

I debugged into my application and found out that the data is changed
correctly in the DataSet, so it seems to me like an refreshing
problem...
Brandon
6/14/2006 11:26:20 AM
Hello,

Try implementing PropertyChanged in your business object, as in the
following snippet. Don't forget to inherit INotifyPropertyChanged. If
you haven't checked it out, the DataBinding FAQ word document is pretty
helpful:

http://www.windowsforms.net/Samples/Go%20To%20Market/Data%20Binding/DataBinding%20FAQ.doc


///Code follows

using System.ComponentModel;

public class MyClass : INotifyPropertyChanged
{
private float fSomeFloat;

public MyClass() { }

public float SomeFloat
{
get { return fSomeFloat; }
private set
{
if (fSomeFloat != value)
{
fSomeFloat = value;
OnPropertyChanged("SomeFloat"); //Put the column
name in quotes
}
}
}

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string p_PropertyName)
{
OnPropertyChanged(new
PropertyChangedEventArgs(p_PropertyName));
}

protected virtual void
OnPropertyChanged(PropertyChangedEventArgs e)
{
if (null != PropertyChanged)
{
PropertyChanged(this, e);
}
}

}



///end code snippet



[quoted text, click to view]
AddThis Social Bookmark Button