New Posts New Posts RSS Feed: Binding to a DevExpress ListBox
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Binding to a DevExpress ListBox

 Post Reply Post Reply
Author
Mark View Drop Down
Newbie
Newbie
Avatar

Joined: 11-Nov-2008
Location: California
Posts: 5
Post Options Post Options   Quote Mark Quote  Post ReplyReply Direct Link To This Post Topic: Binding to a DevExpress ListBox
    Posted: 18-Nov-2008 at 11:34am
Erturkcevik,
 
Here is an example of how to write a DataBinder for a DevExpress ListBoxControl. Use at your own risk. The actual data binding code can get complicated depending on the objects being bound and what the list box does, so I left that out.
 
  public class DevExListBoxDataBinder : ControlDataBinder {
    public override Type ControlType {
      get { return typeof(BaseListBoxControl); }
    }
    protected override double GetBaseFitness(IDataConverter pConverter) {
      return pConverter is ListConverter ? UIFitness.ModeratelyHigh : UIFitness.None;
    }
    public override String BindingPropertyName {
      get { return "SelectedValue"; }
    }
    public override void InitializeControl(Control pControl, ViewDescriptor pDescriptor) {
      base.InitializeControl(pControl, pDescriptor);
      ListConverter converter = pDescriptor.DataConverter as ListConverter;
      BaseListBoxControl control = pControl as BaseListBoxControl;
      // Sorting (if needed) is performed on the list ahead of time
      control.DataSource = converter.List;
      control.DisplayMember = converter.DisplayMember;
      control.ValueMember = converter.ValueMember;
    }
  }
 
 // Somewhere during application initialization
 void AppInit() {
  ...
  ...
  ControlBinderMap.Instance.UpdateMap(typeof(DevExListBoxDataBinder));
  ...
  ...
 }
 
Best wishes,
Mark
Back to Top
erturkcevik View Drop Down
Groupie
Groupie


Joined: 14-Jun-2007
Location: Turkey
Posts: 40
Post Options Post Options   Quote erturkcevik Quote  Post ReplyReply Direct Link To This Post Posted: 14-Nov-2008 at 6:20am
Hi;
Please send me example code, I want know, how working DataBinder using the source of ListBoxDataBinder.cs
 
Best Regards
 
Back to Top
Mark View Drop Down
Newbie
Newbie
Avatar

Joined: 11-Nov-2008
Location: California
Posts: 5
Post Options Post Options   Quote Mark Quote  Post ReplyReply Direct Link To This Post Posted: 12-Nov-2008 at 12:48pm
Just to follow up on this, I wrote a DataBinder using the source of ListBoxDataBinder.cs as a starting point. I only had to change a few lines of code to get it working. Thanks again.
Back to Top
Mark View Drop Down
Newbie
Newbie
Avatar

Joined: 11-Nov-2008
Location: California
Posts: 5
Post Options Post Options   Quote Mark Quote  Post ReplyReply Direct Link To This Post Posted: 12-Nov-2008 at 10:21am
That's what I needed to know. Thank you David.
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 12-Nov-2008 at 10:09am
Mark.
 
You are correct.  There is no DataBinder for the DevEx ListBox control.
 
Here are some of your options:
 
(1) Use a .NET ListBox
 
(2) Write the DataBinder yourself.  If you have a Professional license, you might be able to start with the source for the .NET List Box Data Binder, and modify the source.  This might be very easy or very difficult depending upon the complexity of the DevEx Databinding.
Back to Top
Mark View Drop Down
Newbie
Newbie
Avatar

Joined: 11-Nov-2008
Location: California
Posts: 5
Post Options Post Options   Quote Mark Quote  Post ReplyReply Direct Link To This Post Posted: 11-Nov-2008 at 4:20pm
I'm in the process of swapping out our System.Windows.Forms.ListBox controls with DevExpress.XtraEditors.ListBoxControl controls and I've ran into a snag with the databinding. From what I can tell there is no IdeaBlade data binder for the DevExpress ListBoxControl. I searched through the forums and couldn't find any information so I'm writing to ask for advice.
 
The form I'm working with has two list box controls on it with some buttons in between that allow the user to move items from one list box to the other. The simplified code for databinding looks like this:
private void doBinding() {
 DevExpress.XtraEditors.ListBoxControl availableFieldsListBox =
  new DevExpress.XtraEditors.ListBoxControl();
 DevExpress.XtraEditors.ListBoxControl fieldsToClearListBox =
  new DevExpress.XtraEditors.ListBoxControl();
 BindableList<SomeObject.SomeField>() arrLeft = new BindableList<SomeObject.SomeField>();
 BindableList<SomeObject.SomeField>() arrRight = new BindableList<SomeObject.SomeField>();
 BindableList<SomeObject.SomeField> fieldList = new BindableList<SomeObject.SomeField>();
 ControlBindingManager ctrlBM = new ControlBindingManager(fieldList);
 ctrlBM.Descriptors.Add(availableFieldsListBox, "Description",
  fieldListConverter(fieldList, arrLeft));
 ctrlBM.Descriptors.Add(fieldsToClearListBox, "Description",
  fieldListConverter(fieldList, arrRight));
}
private ListConverter fieldListConverter(BindableList<SomeObject.SomeField> pDatasource,
  BindableList<SomeObject.SomeField> pArr) {
 ListConverter listConverter = new ListConverter(pDatasource, Editability.Optional,
  true, "Description", "Code");
 listConverter.SetList(pArr);
 return listConverter;
}
The application compiles fine, but when I run it I get the following exception:
 
System.NotSupportedException: Could not locate a suitable binder for a ListBoxControl. Are you missing an assembly reference?
 
All of our other DevExpress controls bind without errors. So i'm wondering, what do I have to do to get this to work like it did with the Windows.Forms listbox, or is that possible?
 
Thanks,
Mark Harmon
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down