DataGridView Control Binding Data source

Source: Internet
Author: User



Objective:

Recently heard that the DataGridView control can directly bind the data source, without passing through the layer of humiliation, access to data, really happy fart, and then a think two dogs will not make, deliberately wrote a stupid version of the tutorial ... Also count record life, celebrate Dragon Boat Festival, Zongzi will not give everyone, but everyone can find me to yo. The quantity is limited until the end. --chenchen


--Step
1 Adding Controls



2 Adding a data source

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmde5mtazna==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">



The middle process is not the next step, and the last choice is the field of the table and table each connection gets the database data


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmde5mtazna==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">


33 Components meaning




Adapter control: Connect to a database to get data

DataSet: Storing and getting good data

Tabular controls: Query a DataSet with a well-written SELECT statement, and then display the data



4 Adding a query statement




Then you'll see two more things (in fact, there's a control, just a control that joins the query)


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmde5mtazna==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">


5 using self-generated code

Join the 4th section above, the computer will be the initiative to generate 2 of code


1 adapter linked database, and the data obtained in the dataset

2 Input Number use Query statements to query DataSet output results


Locate the following code and place it in the button's stand-alone event in order to





6 Configuration Table

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmde5mtazna==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmde5mtazna==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">


7 Extended application (empty line and label)

The last line of the query results in a blank line, the following is the code to go blank line

Datagridview1.allowusertoaddrows = False  

Code for each line callout number

Try            e.graphics.drawstring ((E.rowindex + 1). ToString (),                                  E.inheritedrowstyle.font, New SolidBrush (color.cadetblue),                                  e.rowbounds.location.x +, E. ROWBOUNDS.LOCATION.Y + 5)        Catch            MsgBox ("Operation failed")        end Try    End Sub



Summarize:

In fact, this control combines knowledge of connected data, a dataset and a TableAdapter (Fill method), and in fact a process for connecting, getting data, storing, displaying, and this step actually I did it for about 1 hours, and it started out very messy, Later on-line check the information, read two blog, also made, actually learned is not difficult, difficult is because you did not learn.


——————————!

。!

Come on!!

! ——————————

-- chenchen--



DataGridView Control Binding Data source

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.