bindingsource

Binding to nested property only showing first item in list

蹲街弑〆低调 提交于 2019-12-06 12:10:34
I am trying to bind a ListBox Control in C# Winforms in .NET 4.5 to a list of objects that have a nested property that I wish to use for a DisplayMember. It sort of works except that when I set the DisplayMember to the nested property the listbox only shows one item even though there are two items in the list that it is bound to. If I comment out the code for setting the DisplayMember the listBox shows two items. Is this a bug in the framework? I would like to avoid adding another property or overriding ToString() if I can since I am implementing MVP and would like to keep my view logic

ADO.NET databinding bug - BindingSource.EndEdit() changes current position

十年热恋 提交于 2019-12-06 06:13:48
What is the correct order of processing an insert from a data-bound control using BindingSource , DataSet , and TableAdapter ? This is causing me eternal confusion. I have a form that is used to add a new row. Before showing the form, I call: bindingSource.AddNew(); bindingSource.MoveLast(); Upon Save, I call: bindingSource.EndEdit(); tableAdapter.Insert([the row given to me as bindingSource.Current]); The problem is that if I don't call EndEdit() , the changes of the TextBox with the current focus are not saved if I do call EndEdit() , the BindingSource's Current member no longer points to

.NET BindingSource Filter syntax reference

℡╲_俬逩灬. 提交于 2019-12-05 03:44:15
You can use the Filter property of a BindingSource to do SQL like filtering. For example: bindingSource.Filter= "Activated = 1" Is there something like documentation on the exact syntax of this? I would like to check if a field is not DBNull, so i tried "Field != NULL" but it gives a syntax error. The syntax is generally the same as what would you would use in a SQL Where clause, without the "Where", so in this case, it would be bindingSource.Filter = "Field <> NULL"; If you look at msdn docs for BindingSource.Filter you will see this: "To form a filter value, specify the name of a column

Allow user to sort columns from a LINQ query in a DataGridView

允我心安 提交于 2019-12-04 20:12:59
问题 I can't quite work out how to allow a DataGridView populated at runtime to sort (when users click on the column headers) where a LINQ from XML query is the DataSource, via a BindingSource. Dim QueryReOrder = From Q In Query _ Where ((0 - Q.Qualifier) / cmbTSStakeValue.Text) <= 0.1 _ Order By Q.Qualifier Descending _ Select Q Dim bs As New BindingSource bs.DataSource = QueryReOrder DGFindMatch.DataSource = bs Some of the DataGridView's properties are: Sort Nothing String SortProperty Nothing

Using a BindingSource in a UserControl

梦想与她 提交于 2019-12-04 11:18:08
问题 I have a UserControl with multiple fields that I would like to have bound to a BindingSource. I would also like the UserControl to expose some BindingSource property so that it can be dropped on a Form and be bound to the BindingSource on the form. Is there an easy way to do this? I realize that I can rebind all of the controls of the UserControl in its BindSource setter. But this seems wrong. Is there some BindingSource Proxy that will let me link the BindingSource in the user control to the

How do you get the proper mapping name from a binding source bound to a List<T>, or an anonymous type, to use on a DataGridTableStyle?

限于喜欢 提交于 2019-12-03 23:32:49
I'm trying to create a DataGridTableStyle object so that I can control the column widths of a DataGrid. I've created a BindingSource object bound to a List. Actually it's bound to an anonymous type list created though Linq in the following manner (variable names changed for clarity of what I'm doing): List<myType> myList = new List<myType>(someCapacity); . ...populate the list with query from database... . var query = from i in myList select new { i.FieldA, i.FieldB, i.FieldC }; myBindingSource.DataSource = query; myDataGrid.DataSource = myBindingSource; Then I create a DataGridTableStyle

Allow user to sort columns from a LINQ query in a DataGridView

懵懂的女人 提交于 2019-12-03 14:14:17
I can't quite work out how to allow a DataGridView populated at runtime to sort (when users click on the column headers) where a LINQ from XML query is the DataSource, via a BindingSource. Dim QueryReOrder = From Q In Query _ Where ((0 - Q.Qualifier) / cmbTSStakeValue.Text) <= 0.1 _ Order By Q.Qualifier Descending _ Select Q Dim bs As New BindingSource bs.DataSource = QueryReOrder DGFindMatch.DataSource = bs Some of the DataGridView's properties are: Sort Nothing String SortProperty Nothing System.ComponentModel.PropertyDescriptor SupportsAdvancedSorting False Boolean

Updating of BindingSource in WinForms does not update Datasource Collection

梦想与她 提交于 2019-12-03 11:07:33
I want to display a custom collection in a DataGridView in a Windows Forms app. This custom collection implements ICollection , and IEnumerable . I have set up a BindingSource , using the collection as the .DataSource property. The DataGridView is set to use my BindingSource as it's DataSource. When I add a new item to the collection using the BindingSource.Add() method, the DataGridView updates correctly with the new item. The BindingSource DataSource, on the other hand, does not: MyCustomCollection myCollection = new MyCustomCollection(); myCollection.Add(myCustomObject1); myCollection.Add

When is it worth using a BindingSource?

梦想的初衷 提交于 2019-12-03 08:16:35
问题 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

When is it worth using a BindingSource?

梦想与她 提交于 2019-12-03 01:05:57
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?