Using DataGridView - Newbie question

Using DataGridView - Newbie question

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


Entity posted on Thursday, May 29, 2008

I'm a DBA re-commissioned into a VB programmer role in a CSLA environment, so I apologize if this an absurdly basic question.

I have a Lookups class inheriting BusinessCollectionBase.  I am attempting to bind this to a DataGridView using the following commands:

        _lookups = Lookups.GetLookups("All Types")
        Me.dgvLookups.DataSource = _lookups

It displays all the data, but I don't have a row to add a new row, can't edit any values, and can't delete a row.  Readonly is set to false and all the "AllowUserTo..." are set appropriately.

I haven't added any code to write back the adds, deletes, and updates, but I would think I could still place values in the datagrid even if I don't write them back.

I'm guessing I'm making a rookie mistake, because I'm a rookie.  Could someone please point me in the right direction?  Am I using the wrong type of class? 

Many thanks!

RockfordLhotka replied on Thursday, May 29, 2008

Assuming Lookups is a BusinessListBase, what you need to do is add code in its constructor to enable those features:

Private Sub New()
  AllowNew = True
  ' ...
End Sub

And if you allow new, then you must also override AddNewCore() as discussed in Expert 2005 Business Objects, and illustrated in the ProjectTracker sample app.

Entity replied on Friday, May 30, 2008

Rocky and Joe,

Thanks both for your help.  I now have the "Add New" line showing up in the datagridview, so that is awesome!  I still can't edit any values in there though.

I tried overriding AddNewCore() as shown in E2BO, but it looks like this doesn't exist in the version of CSLA (1.51?) this app is built on (much of it is inherited code).  Is converting to version 2.0 or 3.04 difficult?  Is there backwards compatibility built in or will I end up changing a lot of code?

Thanks!

-Joshua

JoeFallon1 replied on Friday, May 30, 2008

There were some late changes on CSLA 1.x which I never made (rule handling, etc.)

This made the transition to CSLA 2. x enormously difficult. The pain was well worth the effort but it took 4 developers almost a month to convert the large app we have been developing. I have older posts with more detail but it was not a simple exercise.

Given your current situation and exeprience I would not recommend an upgrade.

Joe

 

 

Entity replied on Friday, May 30, 2008

Joe and Rocky,

Thanks for your help!  You've certainly given me some areas to research and some approaches to consider.

I noticed that Jeff Zuerlein once suggested a best practices area for the datagridview for CSLA.  That sounds like a great idea.  Unfortunately, all I would be able to contribute at this point is how not to do it.

Thanks!

-Joshua

RockfordLhotka replied on Friday, May 30, 2008

AddNewCore() comes from BindingList<T> (or perhaps Collection<T>?). That’s a .NET 2.0 feature, and so CSLA 1.x couldn’t use it.

 

However, IBindingList existed in .NET 1.x, and is used by CSLA 1.x. And that interface defines the concept of adding a new item. I must confess that I don’t remember how I had it working back then, but I’m pretty sure CSLA supported the concept of adding new items to a collection via IBindingList.

 

Rocky

 

JoeFallon1 replied on Thursday, May 29, 2008

I think you have to have an override for AddNewCore in your collection class which returns a New item of the BO in the collection initialized however you want.

Joe

 

Copyright (c) Marimer LLC