Very annoying datagrid problem

S

Stef

Hello folks,
The problem I have is this: I have a datagrid with custom column
styles.
I bind this grid to a DataSet then I use the CurrencyManager to handle
the PositionChanged event.
The problem is I get this error saying "No value for index 1" and the
grid becomes a huge red X when I change some data in an item and then
click on the item underneath which is an empty grid row...
I'm puzzled...

Someone can help?

Thanks

Here's the code:

....
private void frmMain_Load(object sender, System.EventArgs e)
{
BindAccounts();
SetOperationGridColumns(Enums.GridMode.EditMode);

BindHisto();
SetHistoGridColumns();

BindGestionnaires();
SetDestinataireGridColumns(Enums.GridMode.EditMode);


}
....

private void BindAccounts()
{
this.dsOperations1.Clear();
this.OperationAdapter.Fill(this.dsOperations1,"qryGetAllOperations");
this.dsOperations1.Tables["qryGetAllOperations"].Columns["AD_Statut"].DefaultValue
= false;
this.dsOperations1.Tables["qryGetAllOperations"].Columns["Script_Statut"].DefaultValue
= false;
this.dsOperations1.Tables["qryGetAllOperations"].Columns["Archive_Statut"].DefaultValue
= false;
this.dsOperations1.Tables["qryGetAllOperations"].Columns["Email_Statut"].DefaultValue
= false;
this.dsOperations1.Tables["qryGetAllOperations"].Columns["KeepAlive_Statut"].DefaultValue
= false;
this.dsOperations1.Tables["qryGetAllOperations"].Columns["Deleted"].DefaultValue
= false;

CurrencyManager cmOperations =
(CurrencyManager)this.BindingContext[this.dbgOperations.DataSource,
this.dbgOperations.DataMember];
cmOperations.PositionChanged += new
EventHandler(CurrentOperationRowChanged);
cmOperations.ItemChanged += new
ItemChangedEventHandler(CurrentOperationItemChanged);

this.dbgOperations.DataSource=this.dsOperations1.Tables["qryGetAllOperations"];
}


private void CurrentOperationRowChanged(object sender, EventArgs e)
{

if(this.dsOperations1.HasChanges())
{
DialogResult dr=MessageBox.Show("Vous avez des modifications en
cours, voulez-vous les sauvegarder?", "Confirmation de modification.",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr ==DialogResult.Yes)
{
cmdSave_Click(sender, e);
}
}
}
 
S

Stef

Ok, I've played a bit around and noticed that my problem seems related
to this code:
....
private void BindAccounts()
....
CurrencyManager cmOperations =
(CurrencyManager)this.BindingContext[this.dbgOperations.DataSource,
this.dbgOperations.DataMember];
cmOperations.PositionChanged += new
EventHandler(CurrentOperationRowChanged);
....

If I comment out this code, the bug is NEVER happening!
I use the currency manager's PositionChanged event to notify the user
that some changes occured (if DataSet.GetChanges() returns something
that is) after he changed row position in the grid.
Maybe I'm not doing something correctly? Is there a better way to do
this?

Thanks all for reading and possibly help me out with this!

Stef
Hello folks,
The problem I have is this: I have a datagrid with custom column
styles.
I bind this grid to a DataSet then I use the CurrencyManager to handle
the PositionChanged event.
The problem is I get this error saying "No value for index 1" and the
grid becomes a huge red X when I change some data in an item and then
click on the item underneath which is an empty grid row...
I'm puzzled...

Someone can help?

Thanks

Here's the code:

...
private void frmMain_Load(object sender, System.EventArgs e)
{
BindAccounts();
SetOperationGridColumns(Enums.GridMode.EditMode);

BindHisto();
SetHistoGridColumns();

BindGestionnaires();
SetDestinataireGridColumns(Enums.GridMode.EditMode);


}
...

private void BindAccounts()
{
this.dsOperations1.Clear();
this.OperationAdapter.Fill(this.dsOperations1,"qryGetAllOperations");
this.dsOperations1.Tables["qryGetAllOperations"].Columns["AD_Statut"].DefaultValue
= false;
this.dsOperations1.Tables["qryGetAllOperations"].Columns["Script_Statut"].DefaultValue
= false;
this.dsOperations1.Tables["qryGetAllOperations"].Columns["Archive_Statut"].DefaultValue
= false;
this.dsOperations1.Tables["qryGetAllOperations"].Columns["Email_Statut"].DefaultValue
= false;
this.dsOperations1.Tables["qryGetAllOperations"].Columns["KeepAlive_Statut"].DefaultValue
= false;
this.dsOperations1.Tables["qryGetAllOperations"].Columns["Deleted"].DefaultValue
= false;

CurrencyManager cmOperations =
(CurrencyManager)this.BindingContext[this.dbgOperations.DataSource,
this.dbgOperations.DataMember];
cmOperations.PositionChanged += new
EventHandler(CurrentOperationRowChanged);
cmOperations.ItemChanged += new
ItemChangedEventHandler(CurrentOperationItemChanged);

this.dbgOperations.DataSource=this.dsOperations1.Tables["qryGetAllOperations"];
}


private void CurrentOperationRowChanged(object sender, EventArgs e)
{

if(this.dsOperations1.HasChanges())
{
DialogResult dr=MessageBox.Show("Vous avez des modifications en
cours, voulez-vous les sauvegarder?", "Confirmation de modification.",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr ==DialogResult.Yes)
{
cmdSave_Click(sender, e);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top