c# - From DataTable to BindingList -
I am in the process of switching from the DataTable to the binding list. I can force DataTable with the DataGrid object.
Here's my dilemma: While I definitely look at the benefits of switching, my circumstances get a little complicated and I'm wondering if it's worth it to switch or not.
My scenario: I have a data grade that shows chemical samples. There are 5 types of sample types, where the columns in the grid will vary for each type (and sometimes within the same type depending on other criteria). Some columns remain the same, some are present in 3 types, some are in 4 etc. Not a simple warship case at all. Currently, I have a datatlet that makes it easy because I can load whatever column I want to do without the properties of each sample which is what I have to do if I use the binding list but then The binding list will make it very easy under the road to refer to sample properties.
This is my first experience with this object (binding list), so any suggestions are welcome. I know that the binding is linked to properties from the list so if I have:
< Pre> public class sample {secure string m_seq; Secure string m_id; Safe string m_weight; Safe string m_units; Public Sample () {} Public String Seq {get {return m_seq; } Set {m_seq = value; }} Public string id {get {return m_id; } Set {m_id = value; }} Public string weight {received {return m_weight; } Set {m_weight = value; }} Public string units {get {return m_units; } Set {m_units = value; } If I have something like this then the grid will be bound to sample class property
binding sample = new binding list and lieutenant; Sample & gt; ();
Which means that I'm going to have 6 types of samples, the final heritage structure, defined with all the properties, can be complex, so I'm wondering if it's worth it. Any feedback is welcome.
I am using c # 2.0; This is a windows app.
If you are using DataGrid
, then there is no one Can you switch to DataGridView
? It will be very flexible ...
I'm not coming completely from the question, but:
If the property is fixed, but you do not want to show everyone Column
Then just add AutoGenerateColumns = false
before adding data, and add the column you want; Alternatively, leave it enabled and just set the .Visible = false
column to the one you do not want to see.
If the property is dynamic on runtime
then it becomes difficult; You're getting in the dark corner of System.ComponentModel
; You can do this via DataGridView
with the ITypedList
(which allows different definitions in each list) or with TypeDescriptionProvider
(which For example, per type or per list, for example) - but among them, only TypeDescriptionProvider
will work with the binding list & lt; T & gt;
Honestly, I do not think this is what you mean; And if so, then it would be easy to stick to DataTable
(both are very difficult to implement correctly).
I hope that helps; And I hope this is as simple as hiding some columns! If I have missed this point, then tell me.
Comments
Post a Comment