Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Sunday, March 14, 2010 5:10 AM
hi friend,
DataGridView control has two properties DataSource and DataBinding, what would be their main difference?
thanks
All replies (5)
Sunday, March 14, 2010 7:10 AM ✅Answered | 1 vote
DataSource property is for DataGridView itself and is the data source that the DataGridView is displaying data for.
But DataBindings property comes from Control because DataGridView inherits from Control.
With DataBindings property, you can bind the control properties to a data source. e.g. you can bind it's visibility to a boolean field of a record.
However you mention DataBinding which I guess it's a typo mistake because it's not a property, it's an event which will fire when data bounded.My Blog - MSDN Complement By Providing Visual C# Walkthroughs and Sample Codes - Founded In February 24, 2010
Sunday, March 14, 2010 7:28 AM ✅Answered
From msdn
DataGridView. DataSource Property
Gets or sets the data source that the DataGridView is displaying data for.
The DataGridView class supports the standard Windows Forms data-binding model. This means the data source can be of any type that implements one of the following interfaces:
The IList interface, including one-dimensional arrays.
The IListSource interface, such as the DataTable and DataSet classes.
The IBindingList interface, such as the BindingList< T> class.
The IBindingListView interface, such as the BindingSource class.
Control. DataBindings Property
Gets the data bindings for the control.
Use the DataBindings property to access the ControlBindingsCollection . By adding Binding objects to the collection, you can bind any property of a control to the property of an object.
Thanks, A.m.a.L Dot Net Goodies |
|
Don't hate the hacker, hate the code |
Sunday, March 14, 2010 7:50 AM ✅Answered
Yes, its DataBindings.
protected void BindControls()
{
/* Create two Binding objects for the first two TextBox
controls. The data-bound property for both controls
is the Text property. The data source is a DataSet
(ds). The data member is specified by a navigation
path in the form : TableName.ColumnName. */
textBox1.DataBindings.Add(new Binding
("Text", ds, "customers.custName"));
textBox2.DataBindings.Add(new Binding
("Text", ds, "customers.custID"));
/* Bind the DateTimePicker control by adding a new Binding.
The data member of the DateTimePicker is specified by a
navigation path in the form: TableName.RelationName.ColumnName. */
DateTimePicker1.DataBindings.Add(new
Binding("Value", ds, "customers.CustToOrders.OrderDate"));
/* Create a new Binding using the DataSet and a
navigation path(TableName.RelationName.ColumnName).
Add event delegates for the Parse and Format events to
the Binding object, and add the object to the third
TextBox control's BindingsCollection. The delegates
must be added before adding the Binding to the
collection; otherwise, no formatting occurs until
the Current object of the BindingManagerBase for
the data source changes. */
Binding b = new Binding
("Text", ds, "customers.custToOrders.OrderAmount");
b.Parse += new ConvertEventHandler(CurrencyStringToDecimal);
b.Format += new ConvertEventHandler(DecimalToCurrencyString);
textBox3.DataBindings.Add(b);
/*Bind the fourth TextBox to the Value of the
DateTimePicker control. This demonstrates how one control
can be bound to another.*/
textBox4.DataBindings.Add("Text", DateTimePicker1,"Value");
BindingManagerBase bmText = this.BindingContext[
DateTimePicker1];
/* Print the Type of the BindingManagerBase, which is
a PropertyManager because the data source
returns only a single property value. */
Console.WriteLine(bmText.GetType().ToString());
// Print the count of managed objects, which is 1.
Console.WriteLine(bmText.Count);
// Get the BindingManagerBase for the Customers table.
bmCustomers = this.BindingContext [ds, "Customers"];
/* Print the Type and count of the BindingManagerBase.
Because the data source inherits from IBindingList,
it is a RelatedCurrencyManager (derived from CurrencyManager). */
Console.WriteLine(bmCustomers.GetType().ToString());
Console.WriteLine(bmCustomers.Count);
/* Get the BindingManagerBase for the Orders of the current
customer using a navigation path: TableName.RelationName. */
bmOrders = this.BindingContext[ds, "customers.CustToOrders"];
}
Thanks, A.m.a.L Dot Net Goodies |
|
Don't hate the hacker, hate the code |
Sunday, March 14, 2010 7:29 AM
However you mention DataBinding which I guess it's a typo mistake because it's not a property, it's an event which will fire when data bounded.
it's **DataBindings **:)
thanks
Thursday, November 10, 2011 11:45 PM
Everyone always shows the VB or C# code for Binding textbox data, no one ever shows how to do it on the ASP Master Page. Could someone please show that process or code?
I am doing a prototype and only want ot have to use the actual programs as a stub and reduce all the typing since the work will be thrown away and redone later. I know that I used to be able to access DB'd in older versions of ASP without writing all kind of program logic, but it seems that is no longer the case. If there is a way could someone please give me the information.
Toni