WPF 4 DataGrid Control (basic functionality)

Source: Internet
Author: User
Tags xmlns

Mention that the DataGrid is used frequently, both for Web pages and for application development. It allows us to flexibly display various data between rows and columns. This article will detail the related features of the DataGrid in WPF 4.

Custom Columns

By default, when we set the Itemsource property for the DataGrid control, the DataGrid automatically generates the corresponding columns based on the data type, and the following table lists the four columns supported by the DataGrid and their data types.

When you create a DataGrid, you can add custom columns by setting whether the columns are automatically generated by the AutoGenerateColumns property. If the DataGrid contains both auto-generated columns and user-defined columns, create user-defined columns first. These four columns are created separately in the following code instance:

<window x:class= "Wpf4controltest.mainwindow"
Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns:local= "Clr-namespace:wpf4controltest"
Xmlns:assembly= "Clr-namespace:system;assembly=mscorlib"
Title= "MainWindow" height= "width=" >
<objectdataprovider x:key= "Sexenum" methodname= "GetValues"
Objecttype= "{x:type Assembly:enum}" >
<x:type type= "Local:sexopt"/>
<datagrid x:name= "DataGrid" itemssource= "{Binding}" autogeneratecolumns= "False" >
<datagridtextcolumn header= "name" width= "binding=" {Binding Name} "/>
<datagridtextcolumn header= "Age" width= "a" binding= "{Binding age}"/>
<datagridcomboboxcolumn width= "header=" Sex "
selecteditembinding= "{Binding Sex}"
Itemssource= ' {Binding source={staticresource sexenum} '/>
<datagridcheckboxcolumn header= "pass Exam?" Width= "100"
Binding= "{Binding pass}"/>
<datagridhyperlinkcolumn header= "Email" width= "150"
binding= "{Binding Email}"/>

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.