HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Binding FlowLayoutPanel

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
flowlayoutpanelbindingstackoverflow

Problem

I'm trying to create a Bindable FlowLayoutPanel that can take a DataSource and map it the specified generic parameter ` controls. Only minimal requirements are to have a selectable index and to be able to change the background color of the selected and deselected controls. I've tried to leave out the implementation of the selected index except for obvious cases. This leaves the option to the developer as to how to move the selected index when a control is added/removed/etc. I have an example program that uses the below and it seems to work ok (it's not very large, but too big to post here).

I was hoping someone else could take a look at this and see if there are any obvious issues.

``
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Design;

namespace DataBindingListOfUserControls
{
///
/// Create a Bindable FlowLayoutPanel
///
/// The control type that will be in the FlowLayoutPanel
/// Note!!! If you wish to use this in a designer, you must create a class
/// that does not use or derive from this generic class. For example, doing something
/// like: BindableFlowLayoutPanel[MyCtrl] would give you designer errors. To fix this,
/// you need to create a class that does not derive from the generic class. So you
/// would do this: class MyCtrlBflp : MiddleBflp,
/// then class MiddleBflp : BindableFlowLayoutPanel[MyCtrl] Then you would use
/// MyCtrlBflp from the Toolbox (and you can create an instance of this through the
/// designer)
public partial class BindableFlowLayoutPanel : UserControl, INotifyPropertyChanged
where T : Control, IBindableObject, new()
{
#region Constants
///
/// The constant value if no control is selected
///
private const int NO_SELECTED_INDEX = -1;
#endregion

#region Member Variables
///
/// The data source that will bind to the controls
///
pr

Solution

Turns out I was going about this the wrong way. I updated this to use the CurrencyManager class instead to manage the bindings for me. This was a much better solution.

Context

StackExchange Code Review Q#8816, answer score: 4

Revisions (0)

No revisions yet.