MYSTERY ZILLION တွင် English သို့မဟုတ် Unicode ဖြင့်သာ အသုံးပြုခွင့်ရှိသည်။ ဇော်ဂျီ ၊ ဧရာ စသည်တို့ကို အသုံးပြုခွင့် မရှိ။ Unicode fonts များမှာ Mon3,Yunghkio, Myanamr3 စသည်များ အသုံးပြုနိုင်သည်။ Unicode Guide ကို ဒီမှာ Download ချပါ။ Zawgyi to Unicode Converter
Don't share ebook or software if nobody request. You can find free book websites on here. We are welcome for discussion or asking question instead.

Visual Studio 2005 and C#

edited May 2008 in C#
Hi,
C# 2008 programming.

မှတ်ချက်များ

  • edited January 2008 Administrators
    Hi,

    This thread is about Visual Studio 2005 mainly, but we can still talk about VS.Net in here also.
    ဘယ်နေရာကနေစကြမလဲပြော ...:D
    စောင့်နေမယ် :P
  • edited May 2008 Registered Users
    Simple Data Binding with Binding Sources

    The simplest possible use of a binding source component is as an intermediary between the data you are using for display and the controls that display the data. Consider the simple form class shown in Listing 4.1.
    Listing 4.1. Binding a Grid Through a BindingSource Component

    partial class CustomersForm : Form
    {

    BindingSource m_CustomersBindingSource = new BindingSource();
    DataGridView m_Grid = new DataGridView();
    public CustomersForm()
    {

    InitializeComponent();
    m_Grid.Dock = DockStyle.Fill;
    this.Controls.Add(m_Grid);
    m_Grid.DataSource = m_CustomersBindingSource;
    }

    // Form.Load event handler
    private void OnFormLoad(object sender, EventArgs e)
    {

    CustomersTableAdapter adapter = new CustomersTableAdapter();
    CustomersDataSet.CustomersDataTable customers = adapter.GetData();
    m_CustomersBindingSource.DataSource = customers;
    }

    }

    This form contains a single grid named m_Grid, which has its Dock property set to Fill so that it fills the client area of the form. It also has a member binding source component, to which the grid is data bound. This can all be set up in the constructor, and is typically done by dragging and dropping both the grid and the binding source onto the form and setting the appropriate properties in the designer. However, for now, let's focus on how to do things without the magic of the designer.
    In the event handler for the form load, the code retrieves the Customers data through a table adapter , and then sets the DataSource property on the binding source to the Customers table. Because the grid was already set up with its DataSource property referencing the binding source in the constructor, this is all that is required to load and present the Customers data in the grid.
    Note
    Binding to a DataTable Really Binds to a DataView
    When you bind to a data table within a data set, whether or not it's strongly typed, you are really binding to the default data view exposed by that table. Every table exposes a default data view (an instance of the DataView class), and that is what is really used for data binding.
    You can also explicitly construct a data view for a data table and bind to that, which gives you the flexibility to filter or sort that view to alter the presentation of the data. Alternatively, you can filter and sort data through a BindingSource, as long as the underlying data collection implements the IBindingList interface.


    To change which data is displayed on the grid, you just set the DataSource property on the binding source member and the grid automatically updates. This may not seem like a big win if you only have one control on the form as in this example, but you'll appreciate this if you have numerous controls on a form all bound to the same data source, and you need to programmatically switch the data source. Picture a data input form where you are editing all the columns for a customer or employee record. In the days before binding sources, if you needed to change the data source that each control was bound to, that meant programmatically resetting the data source binding on each individual control. Now you just need to change it in one placeon the binding sourceand all of the controls bound to the binding source automatically switch to using the new data source.
    A common situation when you might do this is while working with custom business objects. In that case, you might not retrieve an entire collection of objects, such as customers, into memory at once. You might get them one at a time as needed for editing or viewing the customer details. For example, if you were binding a form with input controls for a customer object's individual properties so the user could edit that customer, you might query individually for customer objects based on their name or some identifier, and then you could update the data source for the binding source to be the retrieved customer object. For the user to edit a different customer, you would retrieve that object and set it as the data source for the binding source, and all the controls would update automatically to this new data source's contents.
    Binding sources can also be shared by more than one form. For example, to provide a simple form to let users edit certain columns of a customer record when they double-click on the row in the grid in Listing 4.1, you could design a simple form that looks like Figure 4.1.

    Figure 4.1. Customer Editing Form

    aV2AQ2w9.jpg

    You could have this form take the customer ID as a constructor parameter, retrieve the data into the form, edit it, and then save the data back to the database. You would then also need to refresh the main form with the grid after this dialog completes to reflect the change to the underlying data source. Depending on whether the grid itself was editable, this approach could introduce concurrency problems even for a single user in your application, and it is certainly not the most efficient approach in terms of round-trips to the database.
    What you really want is for the two different forms to be working against the same data source in memory. This way you can pass the binding source that the editing form should bind to as a parameter to the editing form's constructor from the customer listing form that launches the editing form, and then the editing form can bind against the provided binding source, as shown in the following code.
    public partial class CustomerEditForm : Form
    {

    public CustomerEditForm(BindingSource bindingSource)
    {

    InitializeComponent();
    m_CompanyNameTextBox.DataBindings.Add("Text", bindingSource,
    "CompanyName");
    m_ContactNameTextBox.DataBindings.Add("Text", bindingSource,
    "ContactName");
    }


    private void OnSave(object sender, EventArgs e)
    {

    Close();
    }

    }

    This form uses simple data binding between the individual text boxes and the appropriate members in the data source through the binding source that was passed to the form. By doing this, as soon as the changes are made in the form, they are automatically reflected in the underlying data, so the grid from the form that launches this form will be synchronized with that data as well. All the Save button needs to do then is close the form and the data will be saved in the client-side data source. If you wanted to persist those changes to the database at that point, you could add code to also call through your data access layer to push the changes down into the database.
Sign In or Register to comment.