DynamicRootList - Winforms Binding Template/Proper Binding Question

DynamicRootList - Winforms Binding Template/Proper Binding Question

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


xAvailx posted on Wednesday, May 06, 2009

CSLA 3.6.1

We are using the dynamic root list to bind to an editable grid. This is the code we use to remove an item from grid:

Private Sub DeleteLogoColor(ByVal logoColorId As Integer)
LogoColorsBindingSource.RaiseListChangedEvents = False
BindingHelper.UnbindBindingSource(LogoColorsBindingSource, False, True)

Try
Dim logoColor As RequestItemLogoColor = mLogoColors.GetItem(logoColorId)
logoColor.Delete()
logoColor = mLogoColors.SaveItem(logoColor)
mLogoColors.Remove(logoColor)

Catch ex As ATBaseException
MessageBox.Show(ex.Message, My.Resources.ATBaseExceptionErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try

BindUI()

LogoColorsBindingSource.RaiseListChangedEvents = True
LogoColorsBindingSource.ResetBindings(True)
End Sub

We are having a problem where if there is an exception thrown an the grid needs to repaint (lost window focus, another window over, etc...) then we get an error with the currency manager because the grid can't find the source (since it is unbound).

What is the current way to handle the binding/unbinding? or should there be no unbinding at all? I am having a hard time finding a template/example for dynamic root list binding to a winform grid.

Thx.

RockfordLhotka replied on Wednesday, May 06, 2009

The idea behind a dynamic list is that you don't unbind it. Nor do you need to write code to remove an item - just let the datagrid control do the removal when the user deletes the row.

xAvailx replied on Wednesday, May 06, 2009

>> list is that you don't unbind
Ok, that is great to know. If we don't unbind, then it works correctly.

>> Nor do you need to write code to remove an item
Well, this particular UI has a "global" to the form delete button, so the user highlights the row and clicks on the delete button. How should we handle this?

Thx.

RockfordLhotka replied on Wednesday, May 06, 2009

You can either have your code tell the datagrid to delete the row (so it
triggers normal data binding behavior), or your code can emulate the normal
data binding behavior that the datagrid would have done.

Most likely, the datagrid, when a row is removed, calls the remove method on
the bindingSource - and if you do that, you should get the correct behavior.

Rocky

tiago replied on Wednesday, May 06, 2009

There is a full commented example in Code Project. Refer to http://forums.lhotka.net/forums/thread/31781.aspx

Copyright (c) Marimer LLC