Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating Custom Data Bound Controls
Message
From
24/11/2009 20:06:09
 
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01436389
Message ID:
01436506
Views:
35
>I guess the question I need answered is what exactly happens when a control is bound? When you set DataMember and DataSource in a grid, how does each row in the table become a row in the grid?
>
>When you bind to a list or combo, how does each row of data in the table become a list item?
>
>Inquiring minds wanna know...


Magic?

Seriously, I never really delved into the "how", other than "how to make it work". If you're using a DataTable (or a BindingSource), they automatically work with databinding. Check this link, "Data Sources Supported By Windows Forms": http://msdn.microsoft.com/en-us/library/f3y6cb0c.aspx. Here's an excerpt:

In Windows Forms, you can bind to a wide variety of structures, from simple objects (simple binding) to complex lists such as ADO.NET data tables (complex binding). For simple binding, Windows Forms supports binding to the public properties on the simple object. Windows Forms list-based binding generally requires that the object support the IList interface or the IListSource interface. Additionally, if you are binding with through a BindingSource component, you can bind to an object that supports the IEnumerable interface. For more information about interfaces related to data binding, see Interfaces Related to Data Binding.

~~Bonnie



>
>
>
>
>>>I have been researching this, and all the examples tell you basically how to drop a data control onto a user control and set the DataSource/DataMember controls via a property.
>>
>>That doesn't always end up being the best way to do this. You have to take examples with a big grain of salt, IMHO.
>>
>>>I want to create my own specialized list control, with my own DataSource and DataMember properties, and when set, have one instance of a row object mapped to a row in a data table.
>>
>>First, what kind of list are you talking about specifically? A ListView or a ListBox control? (Or a List< >? ... which isn't a control.)
>>
>>Secondly, I wouldn't databind to a DataRow ... you want to bind to the DataTable or to a BindingSource (which the developer could set to anything, which may be good or bad, depending on whether you do or do not want to limit what's allowed with your class). I wrote my Framework back in the 1.1 days, and BindingSource was not introduced until 2.0, consequently all of my controls databind to a DataTable.
>>
>>~~Bonnie
>>
>>
>>
>>
>>>I have been researching this, and all the examples tell you basically how to drop a data control onto a user control and set the DataSource/DataMember controls via a property.
>>>
>>>I want to create my own specialized list control, with my own DataSource and DataMember properties, and when set, have one instance of a row object mapped to a row in a data table.
>>>
>>>My first thought was to loop through all the rows in the table and for each row add a row to the list.
>>>
>>>Is there a dynamic way to do this?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform