GRIDCONTROL PROPERTIES

public BaseView MainView get; set; Public Property MainView As BaseView

Property Value

Type Default Description
BaseView null

A BaseView descendant representing the View that displays data at the top hierarchy màn chơi.

Bạn đang xem: Gridcontrol properties

Remarks

When the grid control doesn’t display master-detail data, the View specified by the MainView property is the only View that displays data. By default, when the grid control is created, it initializes the MainView property with a GridView object with default settings. Thus, if you need khổng lồ display data using a Card View, create a new CardView object and assign it to the MainView property.

When using the grid control khổng lồ display master-detail relationships, the MainView property specifies the View that will represent the top level data. This is the data specified by the grid control’s GridControl.DataSource & GridControl.DataMember properties. Detail data is represented by Views stored within the GridControl.LevelTree tree or supplied by the master View’s GridView.MasterRowGetLevelDefaultView sự kiện handler.

Xem thêm: It Girl Là Gì - Nguồn Gốc Và Ý Nghĩa Thật Sự Của It Girl

All Views currently displayed are stored within the GridControl.Views collection. The first element in the collection is the MainView property value. Other elements are added or removed dynamically when detail clones are expanded & collapsed respectively.


NOTE

Do not phối the MainView property while wrapping the setter with the GridControl.BeginUpdate và GridControl.EndUpdate method pair. Instead, phối the MainView property outside the BeginUpdate/EndUpdate block.


Example

The following example creates a GridControl at runtime and shows how to lớn perkhung basic customization tasks:

Bind the grid lớn a data sourceAccess the View that presents the underlying dataAccess columnsAssign an in-place editor (a combobox) to a columnSort & group dataCalculate total and group summariesCreate a filterHide columns & calculate column “best” widthsExpand group rowsFocus a specific cellSpecify DataAnnotation attributes (column display names & data formats) at the data source level

*


using hocvieneq.com.Data;using hocvieneq.com.XtraEditors.Repository;using hocvieneq.com.XtraGrid;using hocvieneq.com.XtraGrid.Columns;using hocvieneq.com.XtraGrid.Views.Grid;using System;using System.ComponentModel;using System.ComponentModel.DataAnnotations;using System.Runtime.CompilerServices;using System.Windows.Forms;namespace WindowsFormsApplication1 { public partial class Form1 : Form public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) GridControl gridControl1 = new GridControl(); gridControl1.Parent = this; gridControl1.Dock = DockStyle.Fill; gridControl1.DataSource = DataHelper.GetData(30); // The grid automatically creates columns for the public fields found in the data source. // Calling the gridView1.PopulateColumns method is not required unless the gridView1.OptionsBehavior.AutoPopulateColumns is disabled // The grid automatically creates a GridView that presents the underlying data as a two-dimensional table. GridView gridView1 = gridControl1.MainView as GridView; // Obtain created columns. GridColumn colCompany = gridView1.Columns<"CompanyName">; GridColumn colID = gridView1.Columns<"ID">; GridColumn colDate = gridView1.Columns<"RequiredDate">; GridColumn colPayment = gridView1.Columns<"Value">; GridColumn colProcessed = gridView1.Columns<"Processed">; // The Company column uses a ComboBox in-place editor that shows a danh mục of available companies. RepositoryItemComboBox riComboBox = new RepositoryItemComboBox(); riComboBox.Items.AddRange(DataHelper.companies); gridControl1.RepositoryItems.Add(riComboBox); colCompany.ColumnEdit = riComboBox; // Hide a column. colID.Visible = false; //Group and sort data. colCompany.GroupIndex = 0; colDate.SortIndex = 0; colDate.SortOrder = hocvieneq.com.Data.ColumnSortOrder.Descending; //Show group columns in the table. gridView1.OptionsView.ShowGroupedColumns = true; // Expand group rows. gridView1.ExpandAllGroups(); // Apply a filter. gridView1.ActiveFilterString = ">= #" + DateTime.Today.ToString() + "#"; //Calculate two total summaries. colDate.Summary.Add(SummaryItemType.Count, colDate.FieldName, "Count=0"); colDate.Summary.Add(SummaryItemType.Max, colDate.FieldName, "Max=0:d"); gridView1.OptionsView.ShowFooter = true; //Calculate group summaries. GridGroupSummaryItem thành tựu = new GridGroupSummaryItem(); vật phẩm.FieldName = colCompany.FieldName; thành phầm.SummaryType = hocvieneq.com.Data.SummaryItemType.Count; gridView1.GroupSummary.Add(item); GridGroupSummaryItem item1 = new GridGroupSummaryItem(); item1.FieldName = colPayment.FieldName; item1.SummaryType = SummaryItemType.Sum; item1.DisplayFormat = "group total=0:c2"; item1.ShowInGroupColumnFooter = colPayment; gridView1.GroupSummary.Add(item1); // Forcibly move sầu group footer summaries lớn positions in group rows under corresponding column headers. gridView1.OptionsBehavior.AlignGroupSummaryInGroupRow = hocvieneq.com.Utils.DefaultBoolean.True; // Focus a specific cell. gridView1.FocusedRowHandle = 1; gridView1.FocusedColumn = colCompany; // Optimize column widths. colDate.BestFit(); colProcessed.BestFit(); public class Record : INotifyPropertyChanged public Record() int id; public int ID get return id; phối if (id != value) id = value; OnPropertyChanged(); string text; public string CompanyName get return text; set if (text != value) if (string.IsNullOrEmpty(value)) throw new Exception(); text = value; OnPropertyChanged(); Nullable val; public Nullable Value get return val; phối if (val != value) val = value; OnPropertyChanged(); DateTime dt; public DateTime RequiredDate get return dt; set if (dt != value) dt = value; OnPropertyChanged(); bool state; public bool Processed get return state; phối if (state != value) state = value; OnPropertyChanged(); public override string ToString() return string.Format("ID = 0, Text = 1", ID, CompanyName); public sự kiện PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged( string propertyName = "") if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); public class DataHelper { public static string<> companies = new string<> "Hanari Carnes", "Que Delícia", "Romero y tomillo", "Mère Paillarde", "Comércio Mineiro", "Reggiani Caseifici", "Maison Dewey" ; public static BindingList GetData(int count) { BindingList records = new BindingList(); Random rnd = new Random(); for (int i = 0; i Imports hocvieneq.com.XtraEditorsImports hocvieneq.com.XtraEditors.RepositoryImports hocvieneq.com.XtraGridImports SystemImports System.Collections.GenericImports System.ComponentModelImports System.ComponentModel.DataAnnotationsImports System.DataImports System.DrawingImports System.LinqImports System.Runtime.CompilerServicesImports System.TextImports System.Threading.TasksImports System.Windows.FormsImports hocvieneq.com.DataImports hocvieneq.com.XtraGrid.Views.GridImports hocvieneq.com.XtraGrid.ColumnsPublic Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dlặng gridControl1 As GridControl = New GridControl() gridControl1.Parent = Me gridControl1.Dochồng = DockStyle.Fill gridControl1.DataSource = DataHelper.GetData(30) ' The grid automatically creates columns for the public fields found in the data source. ' Calling the gridView1.PopulateColumns method is not required unless the gridView1.OptionsBehavior.AutoPopulateColumns is disabled ' The grid automatically creates a GridView that presents the underlying data as a two-dimensional table. Dim gridView1 As GridView = TryCast(gridControl1.MainView, GridView) ' Obtain created columns. Dyên ổn colCompany As GridColumn = gridView1.Columns("CompanyName") Dyên ổn colID As GridColumn = gridView1.Columns("ID") Dim colDate As GridColumn = gridView1.Columns("RequiredDate") Dyên ổn colPayment As GridColumn = gridView1.Columns("Value") Dyên ổn colProcessed As GridColumn = gridView1.Columns("Processed") ' The Company column uses a ComboBox in-place editor that shows a menu of available companies. Dyên ổn riComboBox As RepositoryItemComboBox = New RepositoryItemComboBox() riComboBox.Items.AddRange(DataHelper.companies) gridControl1.RepositoryItems.Add(riComboBox) colCompany.ColumnEdit = riComboBox ' Hide a column. colID.Visible = False 'Group & sort data. colCompany.GroupIndex = 0 colDate.SortIndex = 0 colDate.SortOrder = hocvieneq.com.Data.ColumnSortOrder.Descending 'Show group columns in the table. gridView1.OptionsView.ShowGroupedColumns = True ' Expand group rows. gridView1.ExpandAllGroups() ' Apply a filter. gridView1.ActiveFilterString = ">= #" và DateTime.Today.ToString() & "#" 'Calculate two total summaries. colDate.Summary.Add(SummaryItemType.Count, colDate.FieldName, "Count=0") colDate.Summary.Add(SummaryItemType.Max, colDate.FieldName, "Max=0:d") gridView1.OptionsView.ShowFooter = True 'Calculate group summaries. Dyên ổn chiến thắng As GridGroupSummaryItem = New GridGroupSummaryItem() cống phẩm.FieldName = colCompany.FieldName thắng lợi.SummaryType = hocvieneq.com.Data.SummaryItemType.Count gridView1.GroupSummary.Add(item) Dlặng item1 As GridGroupSummaryItem = New GridGroupSummaryItem() item1.FieldName = colPayment.FieldName item1.SummaryType = SummaryItemType.Sum item1.DisplayFormat = "group total=0:c2" item1.ShowInGroupColumnFooter = colPayment gridView1.GroupSummary.Add(item1) ' Forcibly move group footer summaries to lớn positions in group rows under corresponding column headers. gridView1.OptionsBehavior.AlignGroupSummaryInGroupRow = hocvieneq.com.Utils.DefaultBoolean.True ' Focus a specific cell. gridView1.FocusedRowHandle = 1 gridView1.FocusedColumn = colCompany ' Optimize column widths. colDate.BestFit() colProcessed.BestFit() End SubEnd ClassPublic Class Record Implements INotifyPropertyChanged Public Sub New() End Sub Private id_Renamed As Integer Public Property ID() As Integer Get Return id_Renamed End Get Set(ByVal value As Integer) If id_Renamed value Then id_Renamed = value OnPropertyChanged() End If End Set End Property Private text As String Public Property CompanyName() As String Get Return text End Get Set(ByVal value As String) If text value Then If String.IsNullOrEmpty(value) Then Throw New Exception() End If text = value OnPropertyChanged() End If End Set End Property Private val? As Decimal Public Property Value() As Decimal? Get Return val End Get Set(ByVal value? As Decimal) If Not val.Equals(value) Then val = value OnPropertyChanged() End If End Set End Property Private dt As Date Public Property RequiredDate() As Date Get Return dt End Get Set(ByVal value As Date) If dt value Then dt = value OnPropertyChanged() End If End Set End Property Private state As Boolean Public Property Processed() As Boolean Get Return state End Get Set(ByVal value As Boolean) If state value Then state = value OnPropertyChanged() End If End Set End Property Public Overrides Function ToString() As String Return String.Format("ID = 0, Text = 1", ID, CompanyName) End Function Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged Protected Sub OnPropertyChanged( Optional propertyName As String = "") RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName)) End SubEnd ClassPublic Class DataHelper Public Shared companies() As String = "Hanari Carnes", "Que Delícia", "Romero y tomillo", "Mère Paillarde", "Comércio Mineiro", "Reggiani Caseifici", "Maison Dewey" Public Shared Function GetData(ByVal count As Integer) As BindingList(Of Record) Dyên ổn records As New BindingList(Of Record)() Dlặng rnd As New Random() For i As Integer = 0 To count - 1 Dyên n As Integer = rnd.Next(10) records.Add(New Record() With .ID = i + 100, .CompanyName = companies(i Mod companies.Length), .RequiredDate = Date.Today.AddDays(n - 5), .Value = If(i Mod 2 = 0, (i + 1) * 123, i * 231), .Processed = i Mod 2 = 0 ) Next i Return records End FunctionEnd Class