'宣言 Public Structure FieldLength Inherits System.ValueType
public struct FieldLength : System.ValueType
Imports Infragistics.Windows.DataPresenter Private Sub xamDataGrid1_Initialized(ByVal sender As System.Object, ByVal e As System.EventArgs) Me.InitializeControl(DirectCast(sender, XamDataGrid)) End Sub Private Sub InitializeControl(ByVal grid As XamDataGrid) Dim fl As New FieldLayout() ' explicit logical pixel width Dim fName As New Field() fName.Name = "name" fName.Width = New FieldLength(150) fl.Fields.Add(fName) ' Auto indicates that the size of the field should ' grow as larger data is encountered. Dim fEmail As New Field() fEmail.Name = "email" fEmail.Width = FieldLength.Auto fl.Fields.Add(fEmail) ' InitialAuto indicates that the size of the field ' should be based upon the initial content when the ' field layout is first used. Dim fDept As New Field() fDept.Name = "department" fDept.Width = FieldLength.InitialAuto fl.Fields.Add(fDept) ' Pixel widths can be expressed as px (pixels, pt (Points), ' in (Inches) or cm (Centimeters) just as they can in a WPF ' Grid panel. Normally this is only used from within xaml ' but you can create the associated type converter to use this ' in code. ' Dim fSalary As New Field() fSalary.Name = "salary" Dim converter As New FieldLengthConverter() fSalary.Width = DirectCast(converter.ConvertFromString(".5in"), FieldLength) fl.Fields.Add(fSalary) ' Star values are used to indicate a weight for the field ' and is used to determine how to distribute the fields when ' there is extra space or not enough. Star fields will be ' increased/decreased as needed. ' Dim uf1 As New UnboundField() uf1.Name = "Comments" uf1.Width = New FieldLength(1, FieldLengthUnitType.Star) fl.Fields.Add(uf1) Dim uf2 As New UnboundField() uf2.Name = "Notes" uf2.Width = New FieldLength(2, FieldLengthUnitType.Star) fl.Fields.Add(uf2) ' add the new field layout we define to the datapresenter grid.FieldLayouts.Add(fl) End Sub
using Infragistics.Windows.DataPresenter; private void xamDataGrid1_Initialized(object sender, EventArgs e) { this.InitializeControl(sender as XamDataGrid); } private void InitializeControl(XamDataGrid grid) { FieldLayout fl = new FieldLayout(); // explicit logical pixel width Field fName = new Field(); fName.Name = "name"; fName.Width = new FieldLength(150); fl.Fields.Add(fName); // Auto indicates that the size of the field should // grow as larger data is encountered. Field fEmail = new Field(); fEmail.Name = "email"; fEmail.Width = FieldLength.Auto; fl.Fields.Add(fEmail); // InitialAuto indicates that the size of the field // should be based upon the initial content when the // field layout is first used. Field fDept = new Field(); fDept.Name = "department"; fDept.Width = FieldLength.InitialAuto; fl.Fields.Add(fDept); // Pixel widths can be expressed as px (pixels, pt (Points), // in (Inches) or cm (Centimeters) just as they can in a WPF // Grid panel. Normally this is only used from within xaml // but you can create the associated type converter to use this // in code. // Field fSalary = new Field(); fSalary.Name = "salary"; FieldLengthConverter converter = new FieldLengthConverter(); fSalary.Width = (FieldLength)converter.ConvertFromString(".5in"); fl.Fields.Add(fSalary); // Star values are used to indicate a weight for the field // and is used to determine how to distribute the fields when // there is extra space or not enough. Star fields will be // increased/decreased as needed. // UnboundField uf1 = new UnboundField(); uf1.Name = "Comments"; uf1.Width = new FieldLength(1, FieldLengthUnitType.Star); fl.Fields.Add(uf1); UnboundField uf2 = new UnboundField(); uf2.Name = "Notes"; uf2.Width = new FieldLength(2, FieldLengthUnitType.Star); fl.Fields.Add(uf2); // add the new field layout we define to the datapresenter grid.FieldLayouts.Add(fl); }