c# - Binding to BindingList<T> - choose what to bind? -


Say I have a business object called a sample and I have a binding list of samples. I have 4 properties in a sample Are there.

Can I choose which property are connected to the datagrid or there is no alternative to optimizing such a thing?

Note: I am using Compact Framework, where there is no DataGrid view, as well as Auton Property and DataMember property.

Please keep this in mind when replying.

  BindingList & LT; Sample & gt; Samples = new binding list & lt; Sample & gt; (); DataGridView dgv = New DataGridView (); Dgv.DataSource = Samples;  

This should display every public property as a column on the DataGrid view. If you want to change what qualities are displayed, you also need to do the following:

  dgv.AutoGenerateColumns = false;  

Go to the properties of DataGride View, manually add columns and set DataPropertyName to the data name.

If you created a datagrid video in the code, then the following DGV will create a column and add it.

  DataGride View Columns DGVC = New Datagreat View Column (); Dgvc.Name = "Properties"; Dgvc.HeaderText = "Property A"; Dgvc.DataPropertyName = "Properties"; Dgv.Columns.Add (dgvc);  


Edit

This gives you closer to what you wanted. However, because it uses an anonymous class, you can not use the binding list (which I know). Alternatively, you can create a samplebirding class, in which you only have the properties that you want to display and generate from the list of common samples.

  Sample of public class {public property property A {get; Set; } Public Child Property B {get; Set;} public string asset C {get; Set;} Public Double Property D {get; Set;}} list & lt; Sample & gt; Samples = new list & lt; Samples & gt; (GetSamples ()); Select new {propertyA = sample.PropertyA, PropertyC = sample.PropertyC} by binding specimen samples in samples = samples; Binding List BL / New Binding List (); Bl.DataSource = sampleBinding; Dgv.DataSource = bl; Sample of public square {[Browsable (false)) Public property assets {set; Set} Set   Public Hair Property B {Set;} Public String Property C {Receive; Set;} [Browsable (wrong)] Public Double Property D {get; Set;}}  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -