Home › Forums › WinForms controls › Xceed Grid for WinForms › An attempt was made to select a row that does not belong to
-
AuthorPosts
-
#15676 |
I use grid3.6 in my winform client.
I add a button cell to the grid.When I click the button,the client will show another form to edit the selected row’s value.When I close the edition form,I need to refresh the grid to show the changes.But when i refresh the grid,a exception will happen and tell me “An attempt was made to select a row that does not belong to the grid”
Here is the message:
??? System.InvalidOperationException
Message=”An attempt was made to select a row that does not belong to a grid.”
Source=”Xceed.Grid”
StackTrace:
? Xceed.Grid.Row.SetSelected(Boolean isSelected)
? Xceed.Grid.Collections.SelectedRowList.ResetTo(Row row)
? Xceed.Grid.GridControl.DoRowSelections(Row oldCurrentRow, Row newCurrentRow, Keys modifierKeys, Boolean rowChangedWithMouse)
? Xceed.Grid.MasterGrid.SelectWithMouse(VisualGridElement gridElement, MouseButtons button, Point mousePosition, Boolean allowCellEdition)
? Xceed.Grid.Cell.OnMouseDown(MouseEventArgs e)
? Xceed.Grid.GridControl.DoMouseDown(MouseEventArgs e)
? Xceed.Grid.GridControl.OnMouseDown(MouseEventArgs e)
? System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
? System.Windows.Forms.Control.WndProc(Message& m)
? Xceed.Grid.GridControl.WndProc(Message& m)
? System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
? System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
? System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
? System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
? System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
? System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
? System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
? System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
? System.Windows.Forms.Form.ShowDialog()
? DataProc.Client.frmMain.???????BToolStripMenuItem_Click(Object sender, EventArgs e) ?? C:\Project\Client\frmMain.cs:?? 149
? System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
? System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
? System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
? System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
? System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
? System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
? System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
? System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
? System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
? System.Windows.Forms.Control.WndProc(Message& m)
? System.Windows.Forms.ScrollableControl.WndProc(Message& m)
? System.Windows.Forms.ToolStrip.WndProc(Message& m)
? System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
? System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
? System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
? System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
? System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
? System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
? System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
? System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
? System.Windows.Forms.Application.Run(Form mainForm)
? DataProc.Client.Program.Main() ?? C:\Project\Client\Program.cs:?? 34
? System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
? System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
? Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
? System.Threading.ThreadHelper.ThreadStart_Context(Object state)
? System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
? System.Threading.ThreadHelper.ThreadStart()Here is my code:
public void button1_Click(object sender, EventArgs e)
{
gridControl1.DataSource = null;
gridControl1.EndInit();
//begin to get data,using a new thread
GetDateDelegate getdate = new GetDateDelegate(InitData);
getdate.BeginInvoke(new AsyncCallback(QueryComplete),null);
}
public virtual void InitData(string where)
{
iadapter.Fill(baseds.Tables[0], where);
}
private void QueryComplete(IAsyncResult ar)
{
if(ar.IsCompleted)
BeginBindDg();
}
public void BeginBindDg()
{
BindGrid initgrid = new BindGrid(InitGrid);
gridControl1.BeginInvoke(initgrid);
}public virtual void InitGrid()
{
gridControl1.EndInit();
gridControl1.BeginInit();
BindingSource bs = new BindingSource();
bs.DataSource = baseds;
bs.DataMember = baseds.Tables[0].TableName;
WinButton saveBtn = new WinButton(“EDIT”);
saveBtn.ButtonType = new ButtonType(ButtonBackgroundImageType.ToolBar, ButtonImageType.User);
gridControl1.Columns.Add(new Column(“EDIT”));
gridControl1.Columns[“EDIT”].CellEditorManager = new CellEditorManager(saveBtn, “”, true, true);
gridControl1.Columns[“EDIT”].CellViewerManager = new CellViewerManager(saveBtn, “”);
gridControl1.Columns[“EDIT”].CellEditorManager.ActivatingControl += new CellEditorEventHandler(CellEditorManager_ActivatingControl);
gridControl1.Columns[“EDIT”].CellEditorManager.DeactivatingControl += new CellEditorEventHandler(CellEditorManager_DeactivatingControl);}
gridControl1.EndInit();
}Imported from legacy forums. Posted by handsomesun (had 2114 views)
You need to get the value of your second form through the first one and not the opposite.
For example, in Form1, you have a grid with some value. With a button press, you start the Form2 in which you edit the value in a TextBox (in this example “TextBox1”). You close you Form2 by setting DialogResult to OK. After, you can get the result in “TextBox1”.
Here is the code I used for this example:
<code>
//Form1
private void button1_Click( object sender, EventArgs e )
{
Form2 form2 = new Form2();
if( form2.ShowDialog() == DialogResult.OK )
{
gridControl1.DataRows[ 0 ].Cells[ 0 ].Value = form2.Controls[“TextBox1”].Text;
}
}//Form2
private void button1_Click( object sender, EventArgs e )
{
this.DialogResult = DialogResult.OK;
}
</code>Imported from legacy forums. Posted by CharlesB (had 3079 views)
-
AuthorPosts
- You must be logged in to reply to this topic.