G
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.ieStringTmpDataSet);
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:
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.ieStringTmpDataSet);
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: