binding source poisiton event executed too many times

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:
 
G

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 said:
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:
 

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