Search Results

Search found 5 results on 1 pages for 'ibindinglist'.

Page 1/1 | 1 

  • Getting IBindingList Property to sort by

    - by Josh
    I've got a class called DatagridBoundList that implements CollectionBase and IBindingList. The implementation of IBindingList.ApplySort looks like this so far: void IBindingList.ApplySort(PropertyDescriptor property, ListSortDirection direction) { throw new NotSupportedException(); } I'm binding the DatagridBoundList to a DataGridView (winforms). When I reflect over the property parameter, I can't seem to find the name of the actual property that the list needs to be sorted by. What's the trick to finding out the name of the property to sort by?

    Read the article

  • Generic IBindingListView Implementations

    - by Brad Leach
    Can anyone suggest a good implementation of a generic collection class that implements the IBindingListView & IBindingList interfaces and provides Filtering and Searching capabilities? I see my current options as: Using a class that someone else has written and tested Inheriting from BindingList, and implementing the IBindingListView interfaces Write a custom collection from scratch, implementing IBindingListView and IBindingList. Obviously, the first option is my preferred choice. Thanking you.

    Read the article

  • When to draw/layout child controls in UserControl

    - by Ted Elliott
    I have a list-type UserControl (like a ListBox). The items inside the control are another complex UserControl containing a few other controls (ComboBox, TextBox, etc). I'm wondering what the preferred or best method would be to override to draw/layout the child controls. I basically want to trigger this method any time the list changes. I originally had a RedrawItems method that I just called whenever I needed to redraw which added or removed Controls from the Controls collection. But it was getting triggered too early in the lifecycle of the code from some of the designer code. Now I've switched to overriding OnLayout and doing my stuff there. I call PerformLayout when I want to trigger a redraw, such as when the DataSource property changes or when it fires a changed event. Is OnLayout the best place for this? Here is the code: [ComplexBindingProperties("DataSource")] public partial class CustomList : UserControl { private object _dataSource; private CustomListItem _newRow; public CustomList() { InitializeComponent(); } protected override void OnCreateControl() { base.OnCreateControl(); _newRow = new CustomListItem(); Controls.Add(_newRow); } public object DataSource { get { return _dataSource; } set { bool register = _dataSource != value; if (_dataSource != null && _dataSource != value) { UnregisterDataSource(_dataSource); } _dataSource = value; if (_dataSource != null) RegisterDataSource(_dataSource); PerformLayout(); } } public CustomListItem ItemTemplate { get { return _newRow; } } protected override void OnLayout(LayoutEventArgs e) { base.OnLayout(e); int ctrlCount = this.Controls.AsEnumerable().OfType<CustomListItem>().Count(); ctrlCount--; // subtract 1 for the add row var ds = this.DataSource as System.Collections.IList; int itemCount = ds == null? 0 : ds.Count; int maxCount = Math.Max(ctrlCount,itemCount); if (maxCount == 0) return; this.SuspendLayout(); // temporarily remove the template Controls.RemoveAt(Controls.Count-1); for (int i = 0; i < maxCount; i++) { CustomListItem item; if (i >= itemCount) { Controls.RemoveAt(i); } else { if (i >= ctrlCount) { item = ItemTemplate.Copy(); this.Controls.Add(item); item.Location = new Point(0, item.Height * i); item.TabIndex = i + 1; item.ViewMode = true; } else { item = (CustomListItem) Controls[i]; } item.Data = ds[i]; } } this.Controls.Add(ItemTemplate); ItemTemplate.Location = new Point(0, ItemTemplate.Height * maxCount); ItemTemplate.TabIndex = maxCount + 1; this.ResumeLayout(true); } private void RegisterDataSource(object dataSource) { IBindingList ds = dataSource as IBindingList; if (ds != null) { ds.ListChanged += new ListChangedEventHandler(DataSource_ListChanged); } } void DataSource_ListChanged(object sender, ListChangedEventArgs e) { switch (e.ListChangedType) { case ListChangedType.ItemAdded: PerformLayout(); break; case ListChangedType.ItemChanged: break; case ListChangedType.ItemDeleted: PerformLayout(); break; case ListChangedType.ItemMoved: PerformLayout(); break; case ListChangedType.Reset: PerformLayout(); break; default: break; } } private void UnregisterDataSource(object dataSource) { IBindingList ds = dataSource as IBindingList; if (ds != null) { ds.ListChanged -= new ListChangedEventHandler(DataSource_ListChanged); } } }

    Read the article

  • C# BindingSource.AddingNew is never called?

    - by msfanboy
    Hello, BindingSource.AddingNew is never called when I leave the cell of my datagrid. The DataGrid has as datasource the BindingSource which again has a "List" of "Customer". What does the BindingSource need to create a new Customer object and add it to the underlying ICustomerList ? Of course a interface has no constructor... Thats the Exception I get: System.MissingMethodException: The constcructor for the type "SAT.EnCoDe.Administration.ICustomer" was not found. bei System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) bei System.SecurityUtils.SecureCreateInstance(Type type, Object[] args) bei System.ComponentModel.BindingList1.AddNewCore() bei System.ComponentModel.BindingList1.System.ComponentModel.IBindingList.AddNew() bei System.Windows.Forms.BindingSource.AddNew() bei System.Windows.Forms.CurrencyManager.AddNew() bei DevExpress.Data.CurrencyDataController.OnCurrencyManagerAddNew() bei DevExpress.Data.CurrencyDataController.AddNewRow() bei DevExpress.XtraGrid.Views.Grid.GridView.OnActiveEditor_ValueModified(Object sender, EventArgs e) bei DevExpress.XtraEditors.Repository.RepositoryItem.RaiseModified(EventArgs e) bei DevExpress.XtraEditors.BaseEdit.OnEditValueChanging(ChangingEventArgs e) bei DevExpress.XtraEditors.TextEdit.OnMaskBox_ValueChanged(Object sender, EventArgs e) bei DevExpress.XtraEditors.Mask.MaskBox.RaiseEditTextChanged() bei System.Windows.Forms.TextBoxBase.WmReflectCommand(Message& m) bei DevExpress.XtraEditors.Mask.MaskBox.BaseWndProc(Message& m) bei DevExpress.XtraEditors.Mask.MaskBox.WndProc(Message& m) bei DevExpress.XtraEditors.TextBoxMaskBox.WndProc(Message& msg) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    Read the article

  • When is it worth using a BindingSource?

    - by Justin
    I think I understand well enough what the BindingSource class does - i.e. provide a layer of indirection between a data source and a UI control. It implements the IBindingList interface and therefore also provides support for sorting. And I've used it frequently enough, without too many problems. But I'm wondering if I use it more often than I should. Perhaps an example would help. Let's say I have just a simple textbox on a form (using WinForms), and I'd like to bind that textbox to a simple property inside a class that returns a string. Is it worth using a BindingSource in this situation? Now let's say I have a grid on my form, and I'd like to bind it to a DataTable. Should I use a BindingSource now? In the latter case, I probably would not use a BindingSource, as a DataTable, from what I can gather, provides the same functionality that the BindingSource itself would. The DataTable will fire the the right events when a row is added, deleted, etc so that the grid will automatically update. But in the first case with the textbox being bound to a string, I would probably have the class that contains the string property implement INotifyPropertyChanged, so that it could fire the PropertyChanged event when the string changes. I would use a BindingSource so that it could listen to these PropertyChanged events so that it could update the textbox automatically when the string changes. How does this sound so far? I still feel like there's a gap in my understanding that's preventing me from seeing the whole picture. This has been a pretty vague question so far, so I'll try to ask some more specific questions - ideally the answers will reference the above examples or something similar... (1) Is it worth using a BindingSource in either of the above examples? (2) It seems that developers just "assume" that the DataTable class will do the right thing, in firing PropertyChanged events at the right time. How does one know if a data source is capable of doing this? Is there a particular interface that a data source should implement in order for developers to be able to assume this behaviour? (3) Does it matter what Control is being bound to, when considering whether or not to use a BindingSource? Or is it only the data source that should affect the decision? Perhaps the answer is (and this would seem logical enough): the Control needs to be intelligent enough to listen to the PropertyChanged events, otherwise a BindingSource is required. So how does one tell if the Control is capable of doing this? Again, is there a particular interface that developers can look for that the Control must implement? It is this confusion that has, in the past, led to me always using a BindingSource. But I'd like to understand better exactly when to use one, so that I do so only when necessary.

    Read the article

1