By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,967 Members | 843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,967 IT Pros & Developers. It's quick & easy.

binding source poisiton event executed too many times

P: n/a
GS
the windows form application works but the eventhandler for binding source
postionChanged got executed too many times: 12 times from saveitemclicked
for the data navigator
many time from additem

here is the code snippet:

I have a datagridview and a detailView

in form load:
Binding regexoptionBinding = regexOptionListBox.DataBindings[0];
regexoptionBinding.Format += new ConvertEventHandler
(this.setRegexoptionsListBoxOnPosnChgd);

// ....

private void setRegexoptionsListBoxOnPosnChgd(object sender,
ConvertEventArgs cevent)
{
addMsg("@@debug in regexBindingSource_positionChanged1 " +
cevent.Value);
if ((cevent.Value == DBNull.Value))
{
cevent.Value = "0";
}
else
{

setRegexoptionsListBox(cevent.Value.ToString()); }
}

private void setRegexoptionsListBox(string sValue)
{
// set regexOptions listbox
if (sValue == "") return;
int iro;

try
{
iro = int.Parse(sValue);
} catch (Exception eip){
setStatus("Warning: invalid Value for regexOptions from
database=" + sValue + CScrlf + eip.Message);
regexOptionListBox.SelectedItem = sValue;
return;
}

regexOptionListBox.SelectedItem =
regexOptionListBox.FindStringExact(sValue);
addMsg("@@debug setRegexoptionsListBox - "
+"RegexOptionListBox set from db "+sValue);
}
the problem is when I click on the save button int eh datanavigator after
changing the RegexOptionListBox to a new value, I will get the event
setRegexoptionsListBox executed 12 times..
I tried changing the code
bool bIgnorePosnChg = false;
private void regexBindingNavigatorSaveItem_Click(object sender,
EventArgs e)
{
bIgnorePosnChg = true;
this.Validate();
this.regexBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.ieStringTm pDataSet);
bIgnorePosnChg = false;
}

and in the beginning of
private void setRegexoptionsListBox(string sValue)
{
if (sValue == "") return;
int iro;

try
{
iro = int.Parse(sValue);
} catch (Exception eip){
setStatus("Warning: invalid Value for regexOptions from
database=" + sValue + CScrlf + eip.Message);
regexOptionListBox.SelectedItem = sValue;
return;
}

regexOptionListBox.SelectedItem =
regexOptionListBox.FindStringExact(sValue);
addMsg("@@debug in setRegexoptionsListBox..selecteditem=" +
regexOptionListBox.SelectedItem + ", selIDX=" +
regexOptionListBox.SelectedIndex + ". value=" +
regexOptionListBox.SelectedValue);
}

and I don't get the first record's RegexoptionsListBox properly selected
that leads to zapping the value to zero!
I am confused. I tried for house looking and different combination and I
still fail to solve the two problem:
Dec 21 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
GS
not sure what went wrong, I deleted a bunch of statements, redesign to
rely on textbox bound to regexoption, for input flue and have the listbox
for regexoption unbound and use formatter that way. the problem of improper
value for first record no longer exist
"GS" <gs**********************@msnews.Nomail.comwrote in message
news:uP**************@TK2MSFTNGP03.phx.gbl...
the windows form application works but the eventhandler for binding source
postionChanged got executed too many times: 12 times from saveitemclicked
for the data navigator
many time from additem

here is the code snippet:

I have a datagridview and a detailView

in form load:
Binding regexoptionBinding =
regexOptionListBox.DataBindings[0];
regexoptionBinding.Format += new ConvertEventHandler
(this.setRegexoptionsListBoxOnPosnChgd);

// ....

private void setRegexoptionsListBoxOnPosnChgd(object sender,
ConvertEventArgs cevent)
{
addMsg("@@debug in regexBindingSource_positionChanged1 " +
cevent.Value);
if ((cevent.Value == DBNull.Value))
{
cevent.Value = "0";
}
else
{

setRegexoptionsListBox(cevent.Value.ToString()); }
}

private void setRegexoptionsListBox(string sValue)
{
// set regexOptions listbox
if (sValue == "") return;
int iro;

try
{
iro = int.Parse(sValue);
} catch (Exception eip){
setStatus("Warning: invalid Value for regexOptions from
database=" + sValue + CScrlf + eip.Message);
regexOptionListBox.SelectedItem = sValue;
return;
}

regexOptionListBox.SelectedItem =
regexOptionListBox.FindStringExact(sValue);
addMsg("@@debug setRegexoptionsListBox - "
+"RegexOptionListBox set from db "+sValue);
}
the problem is when I click on the save button int eh datanavigator after
changing the RegexOptionListBox to a new value, I will get the event
setRegexoptionsListBox executed 12 times..
I tried changing the code
bool bIgnorePosnChg = false;
private void regexBindingNavigatorSaveItem_Click(object
sender,
EventArgs e)
{
bIgnorePosnChg = true;
this.Validate();
this.regexBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.ieStringTm pDataSet);
bIgnorePosnChg = false;
}

and in the beginning of
private void setRegexoptionsListBox(string sValue)
{
if (sValue == "") return;
int iro;

try
{
iro = int.Parse(sValue);
} catch (Exception eip){
setStatus("Warning: invalid Value for regexOptions from
database=" + sValue + CScrlf + eip.Message);
regexOptionListBox.SelectedItem = sValue;
return;
}

regexOptionListBox.SelectedItem =
regexOptionListBox.FindStringExact(sValue);
addMsg("@@debug in setRegexoptionsListBox..selecteditem=" +
regexOptionListBox.SelectedItem + ", selIDX=" +
regexOptionListBox.SelectedIndex + ". value=" +
regexOptionListBox.SelectedValue);
}

and I don't get the first record's RegexoptionsListBox properly selected
that leads to zapping the value to zero!
I am confused. I tried for house looking and different combination and I
still fail to solve the two problem:


Dec 24 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.