I am trying to add data from one table to DataGridView binded to another table.
string
sql = "select a.itemcd from cnitem as a,itemmaster as b,comaster as c where a.itemcd=b.itemcd and b.cocd=c.cocd ";ds =
MainModule.gQuery.PopulateData(sql);for(int i=0;i<ds.Tables[0].Rows.Count; i++){
this.coDnItemBindingSource.AllowNew = true;dgvCoDnItems.Rows.Add();
dgvCoDnItems.Rows[i ].Cells[srNoDataGridViewTextBoxColumn.Index].Value = i + 1;
dgvCoDnItems.Rows[i ].Cells[transNoDataGridViewTextBoxColumn.Index].Value = lblTransNo.Text;
dgvCoDnItems.Rows[i ].Cells[itemCdDataGridViewTextBoxColumn.Index].Value = ds.Tables[0].Rows
[
}
Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.
System.InvalidOperationException was unhandled
Message="Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.DataGridViewRowCollection.Add()
at FA.frmCoDrNote.GenerateDebitNoteButton_Click(Object sender, EventArgs e)
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(Int32 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 FA.StartUp.Main()
at System.AppDomain.nExecuteAssembly(Assembly 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.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()