An unexcepted exception occurs when I call DataRowCollection.Add











up vote
0
down vote

favorite












In the following code:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Diagnostics;

namespace WindowsFormsApplication1
{
public partial class List : Form
{
public List()
{
InitializeComponent();
}

private void List_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 1;
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var cmd = new SQLiteCommand("select * from students", DB.Connection);
var ad = new SQLiteDataAdapter(cmd);
var dt = new DataTable();
ad.Fill(dt);
listBox1.DataSource = dt;
listBox1.DisplayMember = "name";
}

private void btnAdd_Click(object sender, EventArgs e)
{
Debug.Assert(listBox1.DataSource is DataTable);
var dt = listBox1.DataSource as DataTable;
dt.Rows.Add();
btnEdit.Enabled = btnRemove.Enabled = dt.Rows.Count != 0;
}

private void btnEdit_Click(object sender, EventArgs e)
{
Debug.Assert(listBox1.SelectedItem is DataRowView);
new StudentsForm2(listBox1.SelectedItem as DataRowView).ShowDialog(this);
}

private void btnRemove_Click(object sender, EventArgs e)
{
Debug.Assert(listBox1.DataSource is DataTable);
var dt = listBox1.DataSource as DataTable;
dt.Rows.RemoveAt(listBox1.SelectedIndex);
btnEdit.Enabled = btnRemove.Enabled = dt.Rows.Count != 0;
}

private void List_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Close();
}
}

}
}


when the table is empty, I get the following exception:




A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll



Additional information: InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.




in method btnAdd_Click when it calls dt.Rows.Add(). comboBox1 holds tables names, but since I only have one table at the moment it's not used unless for comboBox1_SelectedIndexChanged to be called.



Here's the stack trace at the point the exception is thrown:




at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Windows.Forms.ListBox.set_SelectedIndex(Int32 value)
at System.Windows.Forms.ListControl.DataManager_PositionChanged(Object sender, EventArgs e)
at System.Windows.Forms.CurrencyManager.OnPositionChanged(EventArgs e)
at System.Windows.Forms.CurrencyManager.ChangeRecordState(Int32 newPosition, Boolean validating, Boolean endCurrentEdit, Boolean firePositionChange, Boolean pullData)
at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
at System.Data.DataView.OnListChanged(ListChangedEventArgs e)
at System.Data.DataView.IndexListChanged(Object sender, ListChangedEventArgs e)
at System.Data.DataView.IndexListChangedInternal(ListChangedEventArgs e)
at System.Data.DataViewListener.IndexListChanged(ListChangedEventArgs e)
at System.Data.Index.<>c.b__88_0(DataViewListener listener, ListChangedEventArgs args, Boolean arg2, Boolean arg3)
at System.Data.Listeners1.Notify[T1,T2,T3](T1 arg1, T2 arg2, T3 arg3, Action4 action)
at System.Data.Index.OnListChanged(ListChangedEventArgs e)
at System.Data.Index.OnListChanged(ListChangedType changedType, Int32 index)
at System.Data.Index.InsertRecord(Int32 record, Boolean fireEvent)
at System.Data.Index.ApplyChangeAction(Int32 record, Int32 action, Int32 changeRecord)
at System.Data.Index.RecordStateChanged(Int32 record, DataViewRowState oldState, DataViewRowState newState)
at System.Data.DataTable.RecordStateChanged(Int32 record1, DataViewRowState oldState1, DataViewRowState newState1, Int32 record2, DataViewRowState oldState2, DataViewRowState newState2)
at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean suppressEnsurePropertyChanged, Int32 position, Boolean fireEvent, Exception& deferredException)
at System.Data.DataTable.InsertRow(DataRow row, Int64 proposedID, Int32 pos, Boolean fireEvent)
at System.Data.DataRowCollection.Add(Object values)
at WindowsFormsApplication1.List.btnAdd_Click(Object sender, EventArgs e) in C:UsershamidiDocumentsVisual Studio 2010Projectsm_rezaeeWindowsFormsApplication1WindowsFormsApplication1List.cs:line 44
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WindowsFormsApplication1.Program.Main() in C:UsershamidiDocumentsVisual Studio 2010Projectsm_rezaeeWindowsFormsApplication1WindowsFormsApplication1Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()




I couldn't find any clue about why it happens.










share|improve this question
























  • duplicate: stackoverflow.com/questions/5274357/…
    – JohnB
    Nov 20 at 5:32

















up vote
0
down vote

favorite












In the following code:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Diagnostics;

namespace WindowsFormsApplication1
{
public partial class List : Form
{
public List()
{
InitializeComponent();
}

private void List_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 1;
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var cmd = new SQLiteCommand("select * from students", DB.Connection);
var ad = new SQLiteDataAdapter(cmd);
var dt = new DataTable();
ad.Fill(dt);
listBox1.DataSource = dt;
listBox1.DisplayMember = "name";
}

private void btnAdd_Click(object sender, EventArgs e)
{
Debug.Assert(listBox1.DataSource is DataTable);
var dt = listBox1.DataSource as DataTable;
dt.Rows.Add();
btnEdit.Enabled = btnRemove.Enabled = dt.Rows.Count != 0;
}

private void btnEdit_Click(object sender, EventArgs e)
{
Debug.Assert(listBox1.SelectedItem is DataRowView);
new StudentsForm2(listBox1.SelectedItem as DataRowView).ShowDialog(this);
}

private void btnRemove_Click(object sender, EventArgs e)
{
Debug.Assert(listBox1.DataSource is DataTable);
var dt = listBox1.DataSource as DataTable;
dt.Rows.RemoveAt(listBox1.SelectedIndex);
btnEdit.Enabled = btnRemove.Enabled = dt.Rows.Count != 0;
}

private void List_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Close();
}
}

}
}


when the table is empty, I get the following exception:




A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll



Additional information: InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.




in method btnAdd_Click when it calls dt.Rows.Add(). comboBox1 holds tables names, but since I only have one table at the moment it's not used unless for comboBox1_SelectedIndexChanged to be called.



Here's the stack trace at the point the exception is thrown:




at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Windows.Forms.ListBox.set_SelectedIndex(Int32 value)
at System.Windows.Forms.ListControl.DataManager_PositionChanged(Object sender, EventArgs e)
at System.Windows.Forms.CurrencyManager.OnPositionChanged(EventArgs e)
at System.Windows.Forms.CurrencyManager.ChangeRecordState(Int32 newPosition, Boolean validating, Boolean endCurrentEdit, Boolean firePositionChange, Boolean pullData)
at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
at System.Data.DataView.OnListChanged(ListChangedEventArgs e)
at System.Data.DataView.IndexListChanged(Object sender, ListChangedEventArgs e)
at System.Data.DataView.IndexListChangedInternal(ListChangedEventArgs e)
at System.Data.DataViewListener.IndexListChanged(ListChangedEventArgs e)
at System.Data.Index.<>c.b__88_0(DataViewListener listener, ListChangedEventArgs args, Boolean arg2, Boolean arg3)
at System.Data.Listeners1.Notify[T1,T2,T3](T1 arg1, T2 arg2, T3 arg3, Action4 action)
at System.Data.Index.OnListChanged(ListChangedEventArgs e)
at System.Data.Index.OnListChanged(ListChangedType changedType, Int32 index)
at System.Data.Index.InsertRecord(Int32 record, Boolean fireEvent)
at System.Data.Index.ApplyChangeAction(Int32 record, Int32 action, Int32 changeRecord)
at System.Data.Index.RecordStateChanged(Int32 record, DataViewRowState oldState, DataViewRowState newState)
at System.Data.DataTable.RecordStateChanged(Int32 record1, DataViewRowState oldState1, DataViewRowState newState1, Int32 record2, DataViewRowState oldState2, DataViewRowState newState2)
at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean suppressEnsurePropertyChanged, Int32 position, Boolean fireEvent, Exception& deferredException)
at System.Data.DataTable.InsertRow(DataRow row, Int64 proposedID, Int32 pos, Boolean fireEvent)
at System.Data.DataRowCollection.Add(Object values)
at WindowsFormsApplication1.List.btnAdd_Click(Object sender, EventArgs e) in C:UsershamidiDocumentsVisual Studio 2010Projectsm_rezaeeWindowsFormsApplication1WindowsFormsApplication1List.cs:line 44
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WindowsFormsApplication1.Program.Main() in C:UsershamidiDocumentsVisual Studio 2010Projectsm_rezaeeWindowsFormsApplication1WindowsFormsApplication1Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()




I couldn't find any clue about why it happens.










share|improve this question
























  • duplicate: stackoverflow.com/questions/5274357/…
    – JohnB
    Nov 20 at 5:32















up vote
0
down vote

favorite









up vote
0
down vote

favorite











In the following code:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Diagnostics;

namespace WindowsFormsApplication1
{
public partial class List : Form
{
public List()
{
InitializeComponent();
}

private void List_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 1;
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var cmd = new SQLiteCommand("select * from students", DB.Connection);
var ad = new SQLiteDataAdapter(cmd);
var dt = new DataTable();
ad.Fill(dt);
listBox1.DataSource = dt;
listBox1.DisplayMember = "name";
}

private void btnAdd_Click(object sender, EventArgs e)
{
Debug.Assert(listBox1.DataSource is DataTable);
var dt = listBox1.DataSource as DataTable;
dt.Rows.Add();
btnEdit.Enabled = btnRemove.Enabled = dt.Rows.Count != 0;
}

private void btnEdit_Click(object sender, EventArgs e)
{
Debug.Assert(listBox1.SelectedItem is DataRowView);
new StudentsForm2(listBox1.SelectedItem as DataRowView).ShowDialog(this);
}

private void btnRemove_Click(object sender, EventArgs e)
{
Debug.Assert(listBox1.DataSource is DataTable);
var dt = listBox1.DataSource as DataTable;
dt.Rows.RemoveAt(listBox1.SelectedIndex);
btnEdit.Enabled = btnRemove.Enabled = dt.Rows.Count != 0;
}

private void List_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Close();
}
}

}
}


when the table is empty, I get the following exception:




A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll



Additional information: InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.




in method btnAdd_Click when it calls dt.Rows.Add(). comboBox1 holds tables names, but since I only have one table at the moment it's not used unless for comboBox1_SelectedIndexChanged to be called.



Here's the stack trace at the point the exception is thrown:




at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Windows.Forms.ListBox.set_SelectedIndex(Int32 value)
at System.Windows.Forms.ListControl.DataManager_PositionChanged(Object sender, EventArgs e)
at System.Windows.Forms.CurrencyManager.OnPositionChanged(EventArgs e)
at System.Windows.Forms.CurrencyManager.ChangeRecordState(Int32 newPosition, Boolean validating, Boolean endCurrentEdit, Boolean firePositionChange, Boolean pullData)
at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
at System.Data.DataView.OnListChanged(ListChangedEventArgs e)
at System.Data.DataView.IndexListChanged(Object sender, ListChangedEventArgs e)
at System.Data.DataView.IndexListChangedInternal(ListChangedEventArgs e)
at System.Data.DataViewListener.IndexListChanged(ListChangedEventArgs e)
at System.Data.Index.<>c.b__88_0(DataViewListener listener, ListChangedEventArgs args, Boolean arg2, Boolean arg3)
at System.Data.Listeners1.Notify[T1,T2,T3](T1 arg1, T2 arg2, T3 arg3, Action4 action)
at System.Data.Index.OnListChanged(ListChangedEventArgs e)
at System.Data.Index.OnListChanged(ListChangedType changedType, Int32 index)
at System.Data.Index.InsertRecord(Int32 record, Boolean fireEvent)
at System.Data.Index.ApplyChangeAction(Int32 record, Int32 action, Int32 changeRecord)
at System.Data.Index.RecordStateChanged(Int32 record, DataViewRowState oldState, DataViewRowState newState)
at System.Data.DataTable.RecordStateChanged(Int32 record1, DataViewRowState oldState1, DataViewRowState newState1, Int32 record2, DataViewRowState oldState2, DataViewRowState newState2)
at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean suppressEnsurePropertyChanged, Int32 position, Boolean fireEvent, Exception& deferredException)
at System.Data.DataTable.InsertRow(DataRow row, Int64 proposedID, Int32 pos, Boolean fireEvent)
at System.Data.DataRowCollection.Add(Object values)
at WindowsFormsApplication1.List.btnAdd_Click(Object sender, EventArgs e) in C:UsershamidiDocumentsVisual Studio 2010Projectsm_rezaeeWindowsFormsApplication1WindowsFormsApplication1List.cs:line 44
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WindowsFormsApplication1.Program.Main() in C:UsershamidiDocumentsVisual Studio 2010Projectsm_rezaeeWindowsFormsApplication1WindowsFormsApplication1Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()




I couldn't find any clue about why it happens.










share|improve this question















In the following code:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Diagnostics;

namespace WindowsFormsApplication1
{
public partial class List : Form
{
public List()
{
InitializeComponent();
}

private void List_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 1;
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var cmd = new SQLiteCommand("select * from students", DB.Connection);
var ad = new SQLiteDataAdapter(cmd);
var dt = new DataTable();
ad.Fill(dt);
listBox1.DataSource = dt;
listBox1.DisplayMember = "name";
}

private void btnAdd_Click(object sender, EventArgs e)
{
Debug.Assert(listBox1.DataSource is DataTable);
var dt = listBox1.DataSource as DataTable;
dt.Rows.Add();
btnEdit.Enabled = btnRemove.Enabled = dt.Rows.Count != 0;
}

private void btnEdit_Click(object sender, EventArgs e)
{
Debug.Assert(listBox1.SelectedItem is DataRowView);
new StudentsForm2(listBox1.SelectedItem as DataRowView).ShowDialog(this);
}

private void btnRemove_Click(object sender, EventArgs e)
{
Debug.Assert(listBox1.DataSource is DataTable);
var dt = listBox1.DataSource as DataTable;
dt.Rows.RemoveAt(listBox1.SelectedIndex);
btnEdit.Enabled = btnRemove.Enabled = dt.Rows.Count != 0;
}

private void List_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Close();
}
}

}
}


when the table is empty, I get the following exception:




A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll



Additional information: InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.




in method btnAdd_Click when it calls dt.Rows.Add(). comboBox1 holds tables names, but since I only have one table at the moment it's not used unless for comboBox1_SelectedIndexChanged to be called.



Here's the stack trace at the point the exception is thrown:




at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Windows.Forms.ListBox.set_SelectedIndex(Int32 value)
at System.Windows.Forms.ListControl.DataManager_PositionChanged(Object sender, EventArgs e)
at System.Windows.Forms.CurrencyManager.OnPositionChanged(EventArgs e)
at System.Windows.Forms.CurrencyManager.ChangeRecordState(Int32 newPosition, Boolean validating, Boolean endCurrentEdit, Boolean firePositionChange, Boolean pullData)
at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
at System.Data.DataView.OnListChanged(ListChangedEventArgs e)
at System.Data.DataView.IndexListChanged(Object sender, ListChangedEventArgs e)
at System.Data.DataView.IndexListChangedInternal(ListChangedEventArgs e)
at System.Data.DataViewListener.IndexListChanged(ListChangedEventArgs e)
at System.Data.Index.<>c.b__88_0(DataViewListener listener, ListChangedEventArgs args, Boolean arg2, Boolean arg3)
at System.Data.Listeners1.Notify[T1,T2,T3](T1 arg1, T2 arg2, T3 arg3, Action4 action)
at System.Data.Index.OnListChanged(ListChangedEventArgs e)
at System.Data.Index.OnListChanged(ListChangedType changedType, Int32 index)
at System.Data.Index.InsertRecord(Int32 record, Boolean fireEvent)
at System.Data.Index.ApplyChangeAction(Int32 record, Int32 action, Int32 changeRecord)
at System.Data.Index.RecordStateChanged(Int32 record, DataViewRowState oldState, DataViewRowState newState)
at System.Data.DataTable.RecordStateChanged(Int32 record1, DataViewRowState oldState1, DataViewRowState newState1, Int32 record2, DataViewRowState oldState2, DataViewRowState newState2)
at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean suppressEnsurePropertyChanged, Int32 position, Boolean fireEvent, Exception& deferredException)
at System.Data.DataTable.InsertRow(DataRow row, Int64 proposedID, Int32 pos, Boolean fireEvent)
at System.Data.DataRowCollection.Add(Object values)
at WindowsFormsApplication1.List.btnAdd_Click(Object sender, EventArgs e) in C:UsershamidiDocumentsVisual Studio 2010Projectsm_rezaeeWindowsFormsApplication1WindowsFormsApplication1List.cs:line 44
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WindowsFormsApplication1.Program.Main() in C:UsershamidiDocumentsVisual Studio 2010Projectsm_rezaeeWindowsFormsApplication1WindowsFormsApplication1Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()




I couldn't find any clue about why it happens.







c# datatable system.data.sqlite indexoutofrangeexception






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 6:06









JohnB

1,3581015




1,3581015










asked Nov 20 at 5:20









hamidi

549616




549616












  • duplicate: stackoverflow.com/questions/5274357/…
    – JohnB
    Nov 20 at 5:32




















  • duplicate: stackoverflow.com/questions/5274357/…
    – JohnB
    Nov 20 at 5:32


















duplicate: stackoverflow.com/questions/5274357/…
– JohnB
Nov 20 at 5:32






duplicate: stackoverflow.com/questions/5274357/…
– JohnB
Nov 20 at 5:32



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386665%2fan-unexcepted-exception-occurs-when-i-call-datarowcollection-add%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386665%2fan-unexcepted-exception-occurs-when-i-call-datarowcollection-add%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen