Adding New Row to DevExpress Grid

Adding New Row to DevExpress Grid

Old forum URL: forums.lhotka.net/forums/t/1081.aspx


cash_pat posted on Thursday, August 31, 2006

Hi,

I am unable to add a new row to my DevEx Grid.

I Click in an New Row and enter some data in the first Column. Then I shift to the 2nd Column and get and exception because the data in the 2nd Column is dependent on the First column.

Stepping through the code i found out that neither AddNewCore nor the property corresponsing to the 1st column is being called.

What am doing wrong.

regards

cash pat

ajj3085 replied on Thursday, August 31, 2006

Sounds like the devEx grid doesn't properly support databinding..  It should be calling AddNew to add a new row to the list.

Q Johnson replied on Thursday, August 31, 2006

I am quite surprised you haven't gotten a useful reply on this yet.  There are several very strong users of DevExpress controls in this forum. 

My own experience, so far, is limited to CSLA 1.5 with which the DevExpress grid behaves wonderfully.  I would be VERY surprised if it incapable of data binding as suggested by the other poster.  In my opinion, those kinds of judgement on the scarce sort of information you provided in the first post are nothing but a cheap shot that do a dis-service to those who may be looking for information about competing tool set offerings.

But let's focus on your real problem.  You mention that the second column is dependent on the first column.  Can you give us an explanation (or the actual code) that describes this dependency?  Perhaps your implentation of the validation of the two properties in question has your UI in a no-win position when Property A wants to be populated when Property B isn't?  This sounds more likely to me than a shortcoming in the DevExpress grid. 

But we'll see!

 

 

ajj3085 replied on Thursday, August 31, 2006

Q Johnson:
I would be VERY surprised if it incapable of data binding as suggested by the other poster.  In my opinion, those kinds of judgement on the scarce sort of information you provided in the first post are nothing but a cheap shot that do a dis-service to those who may be looking for information about competing tool set offerings.


I'm sorry your read my post that way, as that's not how it was intended.  However, in general its my understanding that the third party grids implement databinding based on the infrastructure setup in the .Net framework, which would be for the grid to call the AddNew method to add a new item to the collection.  I assumed (perhaps incorrectly) that the OP setup the binding correctly and that the DevEx grid would do that call.  The fact that the AddNewCore is not being called indicates something is going wrong, which at worse is a bug in DevEx.

It could be that the OP didn't setup the binding correctly though too, and that should be ruled out as well.  I am curious to know how the grid is creating the new item (as the item's constructors should be private, internal at most).  At item not created within the framework of Csla (directly via a constructor, for example) could cause things to misbehave.


At any rate, much more actual code being posted would help everyone get to the bottom of this.

Q Johnson replied on Thursday, August 31, 2006

Sorry if the remark seemed unduly harsh.  Thanks for your clarification on intent. I'm happy and hope you are <g>... so to the problem.

Yes, that's my understanding how the grid should handle adding an item, too.  However, it shouldn't try to add the item until the user commits the row by hitting enter or selecting a different row, should it?  The OP said he got an exception when he changed columns - not rows.  We don't even know if he tried to commit the row.  So we surely can't know if AddNew should have fired.  Anyway - no big deal here.

I'm hoping to hear back from him so we can get to the bottom of this.  But I fear he found an unfortunate dependency in validation rules between the two properties bound to the first two columns of his grid and has already solved his problem... which leaves us here wasting time, I guess.

cash_pat replied on Thursday, August 31, 2006

Sorry guys. Xal helped me Solve it. I was missing the AllowNew=true in my constructor

ajj3085 replied on Friday, September 01, 2006

Q Johnson:
Sorry if the remark seemed unduly harsh.  Thanks for your clarification on intent. I'm happy and hope you are <g>... so to the problem.


No offense taken.

Q Johnson:
Yes, that's my understanding how the grid should handle adding an item, too.  However, it shouldn't try to add the item until the user commits the row by hitting enter or selecting a different row, should it? 

No, my understanding is that the new object is created at the moment the new row is added to the grid (so if you're on the last row and start typing in a column, before anything else it will create the new object using AddNew).  It needs to do this, because it needs the new object to store the data the user entered.  If the user commits, EndEdit is called on the object I believe.  If the user cancels, the new row is removed (which is why its important for objects created in AddNewCore to have a unique value returned by GetIdValue and not just -1 for ALL new objects).

Q Johnson:
The OP said he got an exception when he changed columns - not rows.  We don't even know if he tried to commit the row.  So we surely can't know if AddNew should have fired.  Anyway - no big deal here.

No, AddNew should have been fired as soon as the user started editing the first column. 

At any rate, the problem seems to be solved; AllowNew = false WILL raise an exception if its not set on both the collection and the bindingsource. Sounds like it wasn't set on the list, which will cause AddNew to throw.. although it seems that the DevEx grid doesn't call AddNew until the user moves on to the next column.. weird.

Q Johnson replied on Friday, September 01, 2006

re: >>  the new object is created at the moment the new row is added to the grid (so if you're on the last row and start typing in a column, before anything else it will create the new object using AddNew).  It needs to do this, because it needs the new object to store the data the user entered.  If the user commits, EndEdit is called on the object I believe.  If the user cancels, the new row is removed (which is why its important for objects created in AddNewCore to have a unique value returned by GetIdValue and not just -1 for ALL new objects). <<

Thanks for correcting my impression of that.  I guess the grid is trying to add the row after he gave it some data to try and save (as a result of his update of the first column).  If it tried after simply clicking in the new row section of the UI, he wouldn't even have gotten to enter data into that cell, right?.

Good info.  Thanks.  And it's also the expected good news that Dev Express' grid didn't have any trouble in this scenario, once the BO was coded properly.  So everybody's happy.

btw, could you give me a quick pointer on how you select the text from the previous posting to copy here.  It looks like there's a special technique to it that I am not using.

Thanks again.

   

xal replied on Friday, September 01, 2006

Q:
Hit the quote button instead of the reply one and you'll see how it works...

Andrés

ajj3085 replied on Friday, September 01, 2006

Q Johnson:
Thanks for correcting my impression of that.  I guess the grid is trying to add the row after he gave it some data to try and save (as a result of his update of the first column).  If it tried after simply clicking in the new row section of the UI, he wouldn't even have gotten to enter data into that cell, right?.


No problem.  It seems the DevEx grid is a bit different though; the standard grid adds the item as soon as you enter edit mode.  It seems the DevEx one waits until you leave the cell (thus committing the data for that cell to the BO).  At least thats my impression.

Q Johnson:
Good info.  Thanks.  And it's also the expected good news that Dev Express' grid didn't have any trouble in this scenario, once the BO was coded properly.  So everybody's happy.

Yes, I should have probably asked about that first, but its one of those details I forgot about.  Smile [:)]

Q Jhonson:
btw, could you give me a quick pointer on how you select the text from the previous posting to copy here.  It looks like there's a special technique to it that I am not using.

You use <quote user="userName"></quote>, except you use square brackets instead of the angled ones.  If you click Quote instead of reply, you'll see how to do it.

Copyright (c) Marimer LLC