We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Mouse Click Crashes Grid

Hi,
I have a GridGrouping control that is bound to a datatable and if I click the currently selected row I get a NullReferenceException. The Stack has the following information:

Syncfusion.Grouping.CurrentRecordManager.BeginEdit() + 256
Syncfusion.Grouping.Table.BeginEdit() + 49
:
:
etc, etc.

I have the grid being bound in the Page_Init and have a PrimaryKey being setup. I am sure it's something I am forgetting.

I can run the Edit Samples without any trouble but my project is a bit different when dealing with the Database. I read 20 rows of information from a SQL database into a DataTable, build the Primary Key, bind the DataTable to the DataSource and then finally bind the data.

Thanks.
David.

13 Replies

AD Administrator Syncfusion Team November 6, 2006 04:00 PM UTC

Hi David,

We are Looking into this and will get back to you as soon as possible

Thanks,
B.Gokulkumar


AD Administrator Syncfusion Team November 8, 2006 05:16 PM UTC

Hi David,

My apologises for the delay in getting back to you.
We worked for a while to reproduce the issue as you told, but we couldn't reproduce the issue in any other scenario other than Page_Load event. so Could you please update us with sample which causes the issue. It will help us to come up with solutions.

Thanks for using Syncfusion products.

regards,
B.Gokulkumar


GB Gokul B Syncfusion Team November 8, 2006 05:26 PM UTC

Hi David,

My apologises for the delay in getting back to you.
We worked for a while to reproduce the issue as you told, but we couldn't reproduce the issue in any other scenario other than Page_Load event. so Could you please update us with sample which causes the issue. It will help us to come up with solutions.

Thanks for using Syncfusion products.

regards,
B.Gokulkumar


DA David A. Gonzales November 9, 2006 06:19 PM UTC

Since my sample uses a SQL Database table that is over 2.5 million records I will try and give more feed back.

In the Page_Init section I get a DataTable from the database of 20 rows of data (I manage all the paging myself). I then create a Primary Key Column:

GridTableDescriptor primKey = this.GridGroupingControl1.TableDescriptor;
primKey.PrimaryKeyColumns.Add("RowID");

Then do the following:

this.GridGroupingControl1.Datasource = dt; //dt = datatable
this.GridGroupingControl1.Databind();

Then I setup the FormEditMode = useDefaultForm. I then setup all the RowAdding, RowDeleting, etc (which do nothing at this stage of the game).

I then build some menus for the ColumnHeader right-clicks. If I double-click on a row i get the NullReference error in BeginEdit().

Here is what I recently found out. I put a button on my form that when I click it I try and edit the row. This is the code:

this.ShowCurrentRecord(); //display the current data
Record rec = this.GridGroupingControl1.Table.CurrentRecord();
rec.BeginEdit();

The rec object is Null so the BeginEdit() has a NullReference. Does this have to do with me manually binding the grid for each new page of data that I am displaying?

Thanks.
David.


AD Administrator Syncfusion Team November 9, 2006 07:06 PM UTC

Hi David,

I think you are using your own Paging logic and not the default Paging in Grid. Yes, you need to bind the grid for each new page of Data.

This is because we do not cache the Data in viewstate, to reduce the viewstate size and increase the speed. However, work is in progress for providing the DataCaching feature and there will be a provision for this, where you will have to bind the grid only once.


Thanks,
A.Sivakumar


DA David A. Gonzales November 14, 2006 06:15 PM UTC

When I click one of the buttons for my custom paging (ie, Next, Previous, Last, First) I do a postback and in each Button click event I get the next 20 records from the SQL Database (stored in dt) and then do the following:

this.GridGroupingControl1.DataSource = dt;
this.GridGroupingControl1.DataBind();

then rebuild the menu items and update the pagecount, etc. So, I think I am binding the data correctly (at least I can see the data in the grid). Do I need to do something else for binding? Even when the grid is displayed for the first time if I click a selected row it crashes with a NullReference.

This seems so simple on the surface.

Thanks for all your help.

David.


GB Gokul B Syncfusion Team November 15, 2006 06:43 PM UTC

Hi David,

My apologises for the delay in getting back to you. Here are some of my suggestions.

1) As we already mentioned, you need to bind the grid for each new page of Data.
2) Before binding to the datasource for each new page of data, please ensure this.GridGroupingControl1.DataSource is set to null as sample provided in the below forum.

http://www.syncfusion.com/support/Forums/message.aspx?MessageID=49160

please look at the below code also

this.GridGroupingControl1.DataSource=null;
this.GridGroupingControl1.DataSource = dt;
this.GridGroupingControl1.DataBind();


Let us know if this helps.

Thanks for using Syncfusion products.

regards,
B.Gokulkumar


GB Gokul B Syncfusion Team November 15, 2006 07:38 PM UTC

Hi David,

What we were mentioning in our previous post is, If you are following the approach mentioned in this forum we were discussing early, then inside the BindGrid function you have to use the below code.

We set the DataSource to null before updating with a new Datatable, there by clearing any cache made during previous binding.

function BindGrid()
{


this.GridGroupingControl1.DataSource=null;
this.GridGroupingControl1.DataSource = dt;
this.GridGroupingControl1.DataBind();
....
....

}

Let us know if you have any queries

regards,
B.Gokulkumar


DA David A. Gonzales November 15, 2006 08:05 PM UTC

Attached is my code that is having problems. I can select a row but if I try to double-click or click a selected row the system returned a NullReference in the BeginEdit() code somewhere. I am not using a ObjectDataSource but providing my own paging support. The button click events handle the getting the new data in the datatable (dt) and re-binding the data each time. FillGrid(DataTable dt) is the routine that does that. I put in a Button1_Click event that tries to get the selected row and print out some data but the Record rec object is null. I am at a lost as to why this does not work. Again the GetUserInfo2() routine gets the next 20 rows of data from the SQL Server and bind that to the grid. The paging, menus, etc all work but when I try to edit a cell (or row) it fires the NullReference error.

Thanks for all your help.
David.

test2Code.zip


GB Gokul B Syncfusion Team November 16, 2006 06:05 PM UTC

Hi David,

We are currently looking into this and will get back to you at the earliest.

regards,
B.Gokulkumar


GB Gokul B Syncfusion Team November 17, 2006 06:03 PM UTC

Hi David,

Sorry for the delay in getting back to you.

Thanks for attachment, I could see this issue in your sample as you mentioned. The Issue was viewstate is not maintained properly when we try to bind the Grid on subsequent postbacks for any operations. To overcome this issue, we made some investigation reg viewstate and found a workaround to persist the viewstate in subsequent postbacks for any opertions(Editing in this scenario).

I here with attached a sample to overcome the issue you are encountering.

ViewStateForumSample.zip


Here is the description of the sample:

* I have bind the grid using the objectdatasource with own paging logic. you can use either any .net datasource control or Datatable.
* I used session variable to maintain the RowIndex ("stRowIndex" in this sample). which is used to the bind grid accordingly.
* To perform any operation in subsequent postbacks, session state value get changed which will be used again in Init and load to avoid rebinding.

Please let us know if you connot use this workaround in your scenario for any reason. Also let us know if you need more help

regards,
B.Gokulkumar








DA David A. Gonzales December 13, 2006 06:09 PM UTC

Sorry I did not get back to you sooner. Anyway, I was able to apply your method for my problem and it's working just fine. Have the menu popups working with paging and I can edit any record I want. Thanks for all your help.

David.


GB Gokul B Syncfusion Team December 13, 2006 07:48 PM UTC

Hi David,

Thanks for your Update.

Let us know if you need any other assist.

Thanks for using Syncfusion products.

regards,
B.Gokulkumar

Loader.
Live Chat Icon For mobile
Up arrow icon