Hi there,
I got a NullReferenceException when delete last row in a datagrid.
I had hard time to solve since it does not occur in my own code.
I put a datagrid in my inherited user control, then put this control on a
form.
I use DataAdaptor to fill the data table and update database.
I have no problem to delete rows in datagrid, unless it is last row.
If I do delete the last row, use Delete key on my keyboard, it throws
following exception.
Is this a known bug? Or can someone point out the clue I can look at? Since
the delet is not handled by myself, I really don't know how to solve it.
Thanks a lot!
Ryan
System.NullReferenceException: Object reference not set to an instance of an
object.
at System.Windows.Forms.DataGrid.ResetSelection()
at System.Windows.Forms.DataGrid.ResetUIState()
at System.Windows.Forms.DataGrid.SetDataGridRows(Data GridRow[] newRows,
Int32 newRowsLength)
at System.Windows.Forms.DataGrid.DeleteDataGridRows(I nt32 deletedRows)
at System.Windows.Forms.DataGrid.DeleteRows(DataGridR ow[] localGridRows)
at System.Windows.Forms.DataGrid.ProcessGridKey(KeyEv entArgs ke)
at System.Windows.Forms.DataGrid.ProcessDialogKey(Key s keyData)
at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.TextBoxBase.ProcessDialogKey( Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Mes sage& msg)
at
System.Windows.Forms.ThreadContext.System.Windows. Forms.UnsafeNativeMethods+IMsoComponent.FPreTransl ateMessage(MSG&
msg)
at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm) 3 4803
Can you post your code please.
--
Brian Delahunty
Ireland http://briandela.com/blog
INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
started in the southeast of Ireland.
"Ryan Liu" wrote: Hi there,
I got a NullReferenceException when delete last row in a datagrid.
I had hard time to solve since it does not occur in my own code.
I put a datagrid in my inherited user control, then put this control on a form.
I use DataAdaptor to fill the data table and update database.
I have no problem to delete rows in datagrid, unless it is last row.
If I do delete the last row, use Delete key on my keyboard, it throws following exception.
Is this a known bug? Or can someone point out the clue I can look at? Since the delet is not handled by myself, I really don't know how to solve it.
Thanks a lot! Ryan
System.NullReferenceException: Object reference not set to an instance of an object. at System.Windows.Forms.DataGrid.ResetSelection() at System.Windows.Forms.DataGrid.ResetUIState() at System.Windows.Forms.DataGrid.SetDataGridRows(Data GridRow[] newRows, Int32 newRowsLength) at System.Windows.Forms.DataGrid.DeleteDataGridRows(I nt32 deletedRows) at System.Windows.Forms.DataGrid.DeleteRows(DataGridR ow[] localGridRows) at System.Windows.Forms.DataGrid.ProcessGridKey(KeyEv entArgs ke) at System.Windows.Forms.DataGrid.ProcessDialogKey(Key s keyData) at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData) at System.Windows.Forms.TextBoxBase.ProcessDialogKey( Keys keyData) at System.Windows.Forms.Control.PreProcessMessage(Mes sage& msg) at System.Windows.Forms.ThreadContext.System.Windows. Forms.UnsafeNativeMethods+IMsoComponent.FPreTransl ateMessage(MSG& msg) at System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason, ApplicationContext context) at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm)
Hi Brian,
Have you found any problem with my code? Do you need more source code from
me?
Thanks a lot!
Ryan
"Ryan Liu" <rl**@eSpaceSoft.com> дÈëÏûÏ¢ÐÂÎÅ:OG**************@tk2msftngp13.phx.gbl ... Hi Brian,
Thanks for your help. I tied to send email to you from 3 mail server but all failed. I have to post to this group again.
Here are the files related.
a.. SelfDefineAbnormalEndGridControl inherits RefeshDataGeridControl b.. RefeshDataGeridControl use SysUtil to read and upate database. c.. RefeshDataGeridControl is put on SystemManager form, and user can edit, delete data.
All these files are attached. I will high light the codes here.
a.. SysUtil.cs public static MySqlDataAdapter BuildDbAdapterForSelfDefindedAbnormalEnd(IDbConnec tion conn){} return a adapter to read and write back to db.
b.. SelfDefineAbnormalEndGridControl implements RefeshDataGeridControl's RefreshDataImp() function to read data from db.
c.. SystemManager is the form user can interactive with. It has 3 tab pages and quite some code. But for our discussion, it is simple, just a selfDefineAbnormalEndGridControl1 on it, and when form is load, SelfDefineAbnormalEndGridControl UpdateDb() method is called.
You see, when user press Delete key on keyboard, this is function of datagrid, not control by my code. And it throw an exception when the user delete the last row in datagrid.
Thanks a lot for your help! Ryan
"Brian Delahunty" <Br************@discussions.microsoft.com> дÈëÏûÏ¢ÐÂÎÅ:89**********************************@ microsoft.com... Can you post your code please.
-- Brian Delahunty Ireland
http://briandela.com/blog
INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I started in the southeast of Ireland.
"Ryan Liu" wrote:
Hi there,
I got a NullReferenceException when delete last row in a datagrid.
I had hard time to solve since it does not occur in my own code.
I put a datagrid in my inherited user control, then put this control on a form.
I use DataAdaptor to fill the data table and update database.
I have no problem to delete rows in datagrid, unless it is last row.
If I do delete the last row, use Delete key on my keyboard, it throws following exception.
Is this a known bug? Or can someone point out the clue I can look at? Since the delet is not handled by myself, I really don't know how to solve it.
Thanks a lot! Ryan
System.NullReferenceException: Object reference not set to an instance of an object. at System.Windows.Forms.DataGrid.ResetSelection() at System.Windows.Forms.DataGrid.ResetUIState() at System.Windows.Forms.DataGrid.SetDataGridRows(Data GridRow[] newRows, Int32 newRowsLength) at System.Windows.Forms.DataGrid.DeleteDataGridRows(I nt32 deletedRows) at System.Windows.Forms.DataGrid.DeleteRows(DataGridR ow[] localGridRows) at System.Windows.Forms.DataGrid.ProcessGridKey(KeyEv entArgs ke) at System.Windows.Forms.DataGrid.ProcessDialogKey(Key s keyData) at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData) at System.Windows.Forms.TextBoxBase.ProcessDialogKey( Keys keyData) at System.Windows.Forms.Control.PreProcessMessage(Mes sage& msg) at System.Windows.Forms.ThreadContext.System.Windows. Forms.UnsafeNativeMethods+IMsoComponent.FPreTransl ateMessage(MSG& msg) at System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason, ApplicationContext context) at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm)
Proiblen solved, all because I add CurrentCellChanged event, in which, I
select whole row. When I remove it, it is fine.
/// <summary>
/// automatically select whole row
/// make it protected so when the class who inherits it can remove it
by -=
/// this is necessary when child allow delete the last row
/// then this event itself will not fire exception, but it will cause
datagrid internal exception
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void dataGrid_CurrentCellChanged(object sender, EventArgs e)
{
if(this.dataGrid.CurrentRowIndex != -1) //not empty table
{
this.dataGrid.Select(this.dataGrid.CurrentRowIndex );
}
}
"Ryan Liu" <rl**@eSpaceSoft.com> дÈëÏûÏ¢ÐÂÎÅ:Oo**************@TK2MSFTNGP09.phx.gbl ... Hi Brian,
Have you found any problem with my code? Do you need more source code from me?
Thanks a lot! Ryan
"Ryan Liu" <rl**@eSpaceSoft.com> дÈëÏûÏ¢ÐÂÎÅ:OG**************@tk2msftngp13.phx.gbl ... Hi Brian,
Thanks for your help. I tied to send email to you from 3 mail server but all failed. I have to post to this group again.
Here are the files related.
a.. SelfDefineAbnormalEndGridControl inherits RefeshDataGeridControl b.. RefeshDataGeridControl use SysUtil to read and upate database. c.. RefeshDataGeridControl is put on SystemManager form, and user can edit, delete data.
All these files are attached. I will high light the codes here.
a.. SysUtil.cs public static MySqlDataAdapter BuildDbAdapterForSelfDefindedAbnormalEnd(IDbConnec tion conn){} return a adapter to read and write back to db.
b.. SelfDefineAbnormalEndGridControl implements RefeshDataGeridControl's RefreshDataImp() function to read data from db.
c.. SystemManager is the form user can interactive with. It has 3 tab pages and quite some code. But for our discussion, it is simple, just a selfDefineAbnormalEndGridControl1 on it, and when form is load, SelfDefineAbnormalEndGridControl UpdateDb() method is called.
You see, when user press Delete key on keyboard, this is function of datagrid, not control by my code. And it throw an exception when the user delete the last row in datagrid.
Thanks a lot for your help! Ryan
"Brian Delahunty" <Br************@discussions.microsoft.com> дÈëÏûÏ¢ÐÂÎÅ:89**********************************@ microsoft.com... Can you post your code please.
-- Brian Delahunty Ireland
http://briandela.com/blog
INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I started in the southeast of Ireland.
"Ryan Liu" wrote:
Hi there,
I got a NullReferenceException when delete last row in a datagrid.
I had hard time to solve since it does not occur in my own code.
I put a datagrid in my inherited user control, then put this control on a form.
I use DataAdaptor to fill the data table and update database.
I have no problem to delete rows in datagrid, unless it is last row.
If I do delete the last row, use Delete key on my keyboard, it throws following exception.
Is this a known bug? Or can someone point out the clue I can look at? Since the delet is not handled by myself, I really don't know how to solve it.
Thanks a lot! Ryan
System.NullReferenceException: Object reference not set to an instance of an object. at System.Windows.Forms.DataGrid.ResetSelection() at System.Windows.Forms.DataGrid.ResetUIState() at System.Windows.Forms.DataGrid.SetDataGridRows(Data GridRow[] newRows, Int32 newRowsLength) at System.Windows.Forms.DataGrid.DeleteDataGridRows(I nt32 deletedRows) at System.Windows.Forms.DataGrid.DeleteRows(DataGridR ow[] localGridRows) at System.Windows.Forms.DataGrid.ProcessGridKey(KeyEv entArgs ke) at System.Windows.Forms.DataGrid.ProcessDialogKey(Key s keyData) at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData) at System.Windows.Forms.TextBoxBase.ProcessDialogKey( Keys keyData) at System.Windows.Forms.Control.PreProcessMessage(Mes sage& msg) at System.Windows.Forms.ThreadContext.System.Windows. Forms.UnsafeNativeMethods+IMsoComponent.FPreTransl ateMessage(MSG& msg) at System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason, ApplicationContext context) at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm)
This discussion thread is closed Replies have been disabled for this discussion. Similar topics
3 posts
views
Thread by Terrence |
last post: by
|
reply
views
Thread by sarah |
last post: by
|
2 posts
views
Thread by Shannon |
last post: by
|
reply
views
Thread by muralidharan |
last post: by
|
3 posts
views
Thread by Patrick.O.Ige |
last post: by
|
5 posts
views
Thread by Patrick.O.Ige |
last post: by
|
3 posts
views
Thread by postings |
last post: by
|
3 posts
views
Thread by mahtan |
last post: by
|
2 posts
views
Thread by Lars Netzel |
last post: by
| | | | | | | | | | |