Datagridview,datatable,dataview Knowledge Summary

Source: Internet
Author: User
DataGridView Knowledge

1. this.dataGridView1.RowHeadersWidth = 25;//gets and sets the width of the column for the row header (first column)

     

2. This.dataGridView1.AutoResizeColumns ()//Adjusts the width of all columns to fit the contents of all its cells, including the header cell

3. BindingManagerBase: Data Binding

in Visual C # data binding, you've learned how to bind certain fields in a dataset to a property of the WinForm component, so that programmers can customize the form of data display based on the WinForm component. And the WinForm component display at this point can change as the record pointer changes. Thus, the key to browsing data logging is how to change the record pointer. To do this, you use the BindingManagerBase class, whose primary role is to manage objects that are implemented to bind to the same data source. Specifically, you can synchronize components on a Windows Form that have data binding to the same data source. A property "Position" is defined in the BindingManagerBase class to change the data pointer in the BindingManagerBase object. Creating a BindingManagerBase object must use the BindingContext class, in fact, each object that is inherited from the control class has a single BindingContext object. The BindingManagerBase object that implements the data-binding component in most creation forms is obtained using the BindingContext of the form class. To delete a row: Multiple TextBox controls on a WinForm display a record in a table in a database whose data source is bound to a dataset and when the Delete button is pressed, the record in the database table is deleted, but the control is also displayed (because the dataset is not updated). I would like to see the effect of the deletion from the WinForm, that is: The DataSet will also update

  

  

private void Button2_Click (object sender, EventArgs e)

        {

            if (Datagridview1.currentcell = = null)

            {

                MessageBox.Show ("No elements in the table can be deleted");

            }

            else

            {

                BindingManagerBase BMB = (bindingmanagerbase) this.datagridview1.bindingcontext[ This.dataGridView1.DataSource];

                DataRowView DRV = (DataRowView) bmb. Current;

                int position = BMB. Position;

                DataRow dr = DRV. Row;



                Dr. Delete ();

            }

        }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.