How to turn off data binding?

P

Paul Guides

Hi,

my app has a ComboBox bound to a DataTable.

When doing removing all rows by suing this code:

public static void RemoveAllRows( DataSet ds, string tabName ) {
try {
DataTable tab = ds.Tables[ tabName ];
// does not help: tab.BeginInit();
// does not help: tab.BeginLoadData();
DataRowCollection rc = tab.Rows;
rc.Clear();
// does not help: tab.EndLoadData();
// does not help: tab.EndInit();
}
catch( Exception ex ) {
Apt.Exception( "RemoveAllRows: " + tabName, ex );
}
}

There will always be an exception deep inside some databinding
code, which is no wonder because all records where removed and
the ComboBox cannot access the row with index 0.
The exceptions says: + "There is no row at position 0.", which
is right.

So I ask: How can one turn off data binding?

The table will be cleared, then reloaed. And i want to turn
DB off before clearing it and turn it on after loading

Any ideas?

Paul

PS: The call stack


system.data.dll!System.Data.DataView.GetRecord(int recordIndex = 0) + 0x27
bytes
system.data.dll!System.Data.DataView.IsOriginalVersion(int index = 0) +
0x21 bytes

system.data.dll!System.Data.DataRowView.GetColumnValue(System.Data.DataColum
n column = {System.Data.DataColumn}) + 0x22 bytes

system.data.dll!System.Data.DataColumnPropertyDescriptor.GetValue(System.Obj
ect component = {System.Data.DataRowView}) + 0x31 bytes

system.windows.forms.dll!System.Windows.Forms.ListControl.FilterItemOnProper
ty(System.Object item = {System.Data.DataRowView}, string field =
"Nachname") + 0x97 bytes

system.windows.forms.dll!System.Windows.Forms.ListControl.FilterItemOnProper
ty(System.Object item = {System.Data.DataRowView}) + 0x29 bytes
system.windows.forms.dll!System.Windows.Forms.ComboBox.set_Text(string
value = "") + 0x11d bytes
system.windows.forms.dll!System.Windows.Forms.ComboBox.UpdateText() + 0x73
bytes

system.windows.forms.dll!System.Windows.Forms.ComboBox.set_SelectedIndex(int
value = -1) + 0x10e bytes

system.windows.forms.dll!System.Windows.Forms.ListControl.DataManager_Positi
onChanged(System.Object sender =
{System.Windows.Forms.RelatedCurrencyManager}, System.EventArgs e =
{System.EventArgs}) + 0x28 bytes

system.windows.forms.dll!System.Windows.Forms.CurrencyManager.OnPositionChan
ged(System.EventArgs e = {System.EventArgs}) + 0x37 bytes

system.windows.forms.dll!System.Windows.Forms.CurrencyManager.ChangeRecordSt
ate(int newPosition = -1, bool validating = false, bool endCurrentEdit =
true, bool firePositionChange = true, bool pullData = false) + 0x6c bytes

system.windows.forms.dll!System.Windows.Forms.CurrencyManager.UpdateIsBindin
g(bool force = false) + 0xd0 bytes

system.windows.forms.dll!System.Windows.Forms.CurrencyManager.UpdateIsBindin
g() + 0xd bytes

system.windows.forms.dll!System.Windows.Forms.CurrencyManager.List_ListChang
ed(System.Object sender = {System.Data.DataView},
System.ComponentModel.ListChangedEventArgs e =
{System.ComponentModel.ListChangedEventArgs}) + 0x44 bytes

system.data.dll!System.Data.DataView.OnListChanged(System.ComponentModel.Lis
tChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x48
bytes
system.data.dll!System.Data.DataView.IndexListChanged(System.Object sender
= {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e =
{System.ComponentModel.ListChangedEventArgs}) + 0x43 bytes
system.data.dll!System.Data.DataView.FireEvent(System.Data.TargetEvent
targetEvent = IndexListChanged, System.Object sender = {System.Data.Index},
System.EventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x4c
bytes

system.data.dll!System.Data.DataViewListener.IndexListChanged(System.Object
sender = {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e =
{System.ComponentModel.ListChangedEventArgs}) + 0x3d bytes

system.data.dll!System.Data.Index.OnListChanged(System.ComponentModel.ListCh
angedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x29
bytes
system.data.dll!System.Data.Index.Reset() + 0x1c bytes
system.data.dll!System.Data.DataTable.ResetIndexes() + 0x6c bytes
system.data.dll!System.Data.DataTable.Clear() + 0x180 bytes
system.data.dll!System.Data.DataRowCollection.Clear() + 0x11 bytes
kwtools.dll!KwTools.Data.RemoveAllRows(System.Data.DataSet ds =
{System.Data.DataSet}, string tabName = "KundenAPs") Line 407 C#
 
W

William Ryan eMVP

If I could look at the code handling the binding it would help, but you can
set the datasource of the combobox to nothing, or just call clear on the
underlying table and repopulate it.
Paul Guides said:
Hi,

my app has a ComboBox bound to a DataTable.

When doing removing all rows by suing this code:

public static void RemoveAllRows( DataSet ds, string tabName ) {
try {
DataTable tab = ds.Tables[ tabName ];
// does not help: tab.BeginInit();
// does not help: tab.BeginLoadData();
DataRowCollection rc = tab.Rows;
rc.Clear();
// does not help: tab.EndLoadData();
// does not help: tab.EndInit();
}
catch( Exception ex ) {
Apt.Exception( "RemoveAllRows: " + tabName, ex );
}
}

There will always be an exception deep inside some databinding
code, which is no wonder because all records where removed and
the ComboBox cannot access the row with index 0.
The exceptions says: + "There is no row at position 0.", which
is right.

So I ask: How can one turn off data binding?

The table will be cleared, then reloaed. And i want to turn
DB off before clearing it and turn it on after loading

Any ideas?

Paul

PS: The call stack


system.data.dll!System.Data.DataView.GetRecord(int recordIndex = 0) + 0x27
bytes
system.data.dll!System.Data.DataView.IsOriginalVersion(int index = 0) +
0x21 bytes

system.data.dll!System.Data.DataRowView.GetColumnValue(System.Data.DataColum
n column = {System.Data.DataColumn}) + 0x22 bytes

system.data.dll!System.Data.DataColumnPropertyDescriptor.GetValue(System.Obj
ect component = {System.Data.DataRowView}) + 0x31 bytes

system.windows.forms.dll!System.Windows.Forms.ListControl.FilterItemOnProper
ty(System.Object item = {System.Data.DataRowView}, string field =
"Nachname") + 0x97 bytes

system.windows.forms.dll!System.Windows.Forms.ListControl.FilterItemOnProper
ty(System.Object item = {System.Data.DataRowView}) + 0x29 bytes
system.windows.forms.dll!System.Windows.Forms.ComboBox.set_Text(string
value = "") + 0x11d bytes
system.windows.forms.dll!System.Windows.Forms.ComboBox.UpdateText() + 0x73
system.windows.forms.dll!System.Windows.Forms.ComboBox.set_SelectedIndex(int
value = -1) + 0x10e bytes

system.windows.forms.dll!System.Windows.Forms.ListControl.DataManager_Positi
onChanged(System.Object sender =
{System.Windows.Forms.RelatedCurrencyManager}, System.EventArgs e =
{System.EventArgs}) + 0x28 bytes

system.windows.forms.dll!System.Windows.Forms.CurrencyManager.OnPositionChan
ged(System.EventArgs e = {System.EventArgs}) + 0x37 bytes

system.windows.forms.dll!System.Windows.Forms.CurrencyManager.ChangeRecordSt
ate(int newPosition = -1, bool validating = false, bool endCurrentEdit =
true, bool firePositionChange = true, bool pullData = false) + 0x6c bytes

system.windows.forms.dll!System.Windows.Forms.CurrencyManager.UpdateIsBindin
g(bool force = false) + 0xd0 bytes

system.windows.forms.dll!System.Windows.Forms.CurrencyManager.UpdateIsBindin
g() + 0xd bytes

system.windows.forms.dll!System.Windows.Forms.CurrencyManager.List_ListChang
ed(System.Object sender = {System.Data.DataView},
System.ComponentModel.ListChangedEventArgs e =
{System.ComponentModel.ListChangedEventArgs}) + 0x44 bytes

system.data.dll!System.Data.DataView.OnListChanged(System.ComponentModel.Lis
tChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x48
bytes
system.data.dll!System.Data.DataView.IndexListChanged(System.Object sender
= {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e =
{System.ComponentModel.ListChangedEventArgs}) + 0x43 bytes
system.data.dll!System.Data.DataView.FireEvent(System.Data.TargetEvent
targetEvent = IndexListChanged, System.Object sender = {System.Data.Index},
System.EventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x4c
bytes

system.data.dll!System.Data.DataViewListener.IndexListChanged(System.Object
sender = {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e =
{System.ComponentModel.ListChangedEventArgs}) + 0x3d bytes

system.data.dll!System.Data.Index.OnListChanged(System.ComponentModel.ListCh
angedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x29
bytes
system.data.dll!System.Data.Index.Reset() + 0x1c bytes
system.data.dll!System.Data.DataTable.ResetIndexes() + 0x6c bytes
system.data.dll!System.Data.DataTable.Clear() + 0x180 bytes
system.data.dll!System.Data.DataRowCollection.Clear() + 0x11 bytes
kwtools.dll!KwTools.Data.RemoveAllRows(System.Data.DataSet ds =
{System.Data.DataSet}, string tabName = "KundenAPs") Line 407 C#
 
P

Paul Guides

Hi Ryan,

because the code shown below is a general utility,
I do not want to touch the data binding of existing
controls. The combobox is only an example, there
might be much more controls bound to the source.

I want to turn OFF all data binding events and
notifications while modifying the data source.

Paul



William Ryan eMVP said:
If I could look at the code handling the binding it would help, but you can
set the datasource of the combobox to nothing, or just call clear on the
underlying table and repopulate it.
Paul Guides said:
Hi,

my app has a ComboBox bound to a DataTable.

When doing removing all rows by suing this code:

public static void RemoveAllRows( DataSet ds, string tabName ) {
try {
DataTable tab = ds.Tables[ tabName ];
// does not help: tab.BeginInit();
// does not help: tab.BeginLoadData();
DataRowCollection rc = tab.Rows;
rc.Clear();
// does not help: tab.EndLoadData();
// does not help: tab.EndInit();
}
catch( Exception ex ) {
Apt.Exception( "RemoveAllRows: " + tabName, ex );
}
}

There will always be an exception deep inside some databinding
code, which is no wonder because all records where removed and
the ComboBox cannot access the row with index 0.
The exceptions says: + "There is no row at position 0.", which
is right.

So I ask: How can one turn off data binding?

The table will be cleared, then reloaed. And i want to turn
DB off before clearing it and turn it on after loading

Any ideas?

Paul

PS: The call stack


system.data.dll!System.Data.DataView.GetRecord(int recordIndex = 0) + 0x27
bytes
system.data.dll!System.Data.DataView.IsOriginalVersion(int index = 0) +
0x21 bytes
system.data.dll!System.Data.DataRowView.GetColumnValue(System.Data.DataColum
n column = {System.Data.DataColumn}) + 0x22 bytes
system.data.dll!System.Data.DataColumnPropertyDescriptor.GetValue(System.Obj
ect component = {System.Data.DataRowView}) + 0x31 bytes
system.windows.forms.dll!System.Windows.Forms.ListControl.FilterItemOnProper
ty(System.Object item = {System.Data.DataRowView}, string field =
"Nachname") + 0x97 bytes
system.windows.forms.dll!System.Windows.Forms.ListControl.FilterItemOnProper
ty(System.Object item = {System.Data.DataRowView}) + 0x29 bytes
system.windows.forms.dll!System.Windows.Forms.ComboBox.set_Text(string
value = "") + 0x11d bytes
system.windows.forms.dll!System.Windows.Forms.ComboBox.UpdateText() + 0x73
system.windows.forms.dll!System.Windows.Forms.ComboBox.set_SelectedIndex(int
value = -1) + 0x10e bytes
system.windows.forms.dll!System.Windows.Forms.ListControl.DataManager_Positi
onChanged(System.Object sender =
{System.Windows.Forms.RelatedCurrencyManager}, System.EventArgs e =
{System.EventArgs}) + 0x28 bytes
system.windows.forms.dll!System.Windows.Forms.CurrencyManager.OnPositionChan
ged(System.EventArgs e = {System.EventArgs}) + 0x37 bytes
system.windows.forms.dll!System.Windows.Forms.CurrencyManager.ChangeRecordSt
ate(int newPosition = -1, bool validating = false, bool endCurrentEdit =
true, bool firePositionChange = true, bool pullData = false) + 0x6c bytes
system.windows.forms.dll!System.Windows.Forms.CurrencyManager.UpdateIsBindin
g(bool force = false) + 0xd0 bytes
system.windows.forms.dll!System.Windows.Forms.CurrencyManager.UpdateIsBindin
g() + 0xd bytes
system.windows.forms.dll!System.Windows.Forms.CurrencyManager.List_ListChang
ed(System.Object sender = {System.Data.DataView},
System.ComponentModel.ListChangedEventArgs e =
{System.ComponentModel.ListChangedEventArgs}) + 0x44 bytes
system.data.dll!System.Data.DataView.OnListChanged(System.ComponentModel.Lis
tChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x48
bytes
system.data.dll!System.Data.DataView.IndexListChanged(System.Object sender
= {System.Data.Index}, System.ComponentModel.ListChangedEventArgs e =
{System.ComponentModel.ListChangedEventArgs}) + 0x43 bytes
system.data.dll!System.Data.DataView.FireEvent(System.Data.TargetEvent
targetEvent = IndexListChanged, System.Object sender = {System.Data.Index},
System.EventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x4c
bytes
system.data.dll!System.Data.DataViewListener.IndexListChanged(System.Object
sender = {System.Data.Index}, System.ComponentModel.ListChangedEventArgs
e
=
{System.ComponentModel.ListChangedEventArgs}) + 0x3d bytes
system.data.dll!System.Data.Index.OnListChanged(System.ComponentModel.ListCh
angedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x29
bytes
system.data.dll!System.Data.Index.Reset() + 0x1c bytes
system.data.dll!System.Data.DataTable.ResetIndexes() + 0x6c bytes
system.data.dll!System.Data.DataTable.Clear() + 0x180 bytes
system.data.dll!System.Data.DataRowCollection.Clear() + 0x11 bytes
{System.Data.DataSet}, string tabName = "KundenAPs") Line 407 C#
 

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