本文整理汇总了C#中System.Windows.Forms.DataGrid.SetDataBinding方法的典型用法代码示例。如果您正苦于以下问题:C# DataGrid.SetDataBinding方法的具体用法?C# DataGrid.SetDataBinding怎么用?C# DataGrid.SetDataBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGrid
的用法示例。
在下文中一共展示了DataGrid.SetDataBinding方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetSnippetGrid
internal static void SetSnippetGrid(Collection<Snippet> snippets, DataGrid grid)
{
grid.TableStyles.Clear();
DataTable dataSource = SnippetDataGridHelper.ToDataTable(snippets);
grid.SetDataBinding(dataSource, "");
DataGridTableStyle table = new DataGridTableStyle();
grid.TableStyles.Add(table);
grid.SuspendLayout();
grid.TableStyles[0].GridColumnStyles[2].Width = 168;
grid.TableStyles[0].GridColumnStyles[3].Width = 83;
grid.TableStyles[0].GridColumnStyles[4].Width = 83;
grid.TableStyles[0].GridColumnStyles[5].Width = 83;
grid.TableStyles[0].GridColumnStyles[6].Width = 83;
SnippetDataGridHelper.HideColumns(grid);
grid.ResumeLayout();
}
示例2: PopulateDataGrid
private void PopulateDataGrid(DataGrid dataGrid, string parser)
{
if (m_dsParserParameters.Tables[parser].Rows.Count == 0)
{
DataRow row = m_dsParserParameters.Tables[parser].NewRow();
m_dsParserParameters.Tables[parser].Rows.Add(row);
}
dataGrid.SetDataBinding(m_dsParserParameters, parser);
DataView view = CreateDataView(m_dsParserParameters.Tables[parser]);
dataGrid.DataSource = view;
}
示例3: PopulateDataGrid
private void PopulateDataGrid(DataGrid dataGrid, string parser)
{
dataGrid.SetDataBinding(m_dsParserParameters, parser);
DataView view = CreateDataView(m_dsParserParameters.Tables[parser]);
dataGrid.DataSource = view;
dataGrid.TableStyles.Add(new DataGridTableStyle { MappingName = parser, RowHeadersVisible = false, AllowSorting = false });
foreach (DataGridBoolColumn col in dataGrid.TableStyles[0].GridColumnStyles.OfType<DataGridBoolColumn>())
col.AllowNull = false;
}
示例4: RenderMessageList
public static void RenderMessageList( MessageList list, DataGrid control )
{
DataTable table = new DataTable("HeldMessages");
// Action
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "Action";
column.ReadOnly = false;
table.Columns.Add( column );
// From
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "From";
column.ReadOnly = true;
table.Columns.Add( column );
// Subject
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "Subject";
column.ReadOnly = true;
table.Columns.Add( column );
// Sent date
column = new DataColumn();
column.DataType = System.Type.GetType("System.DateTime");
column.ColumnName = "Sent";
column.ReadOnly = true;
table.Columns.Add( column );
// Why held
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "Why Held";
column.ReadOnly = true;
table.Columns.Add( column );
// Id
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "Message ID";
column.ReadOnly = true;
// Make property unique for sanity checking.
column.Unique = true;
table.Columns.Add( column );
// Add Id as primary key
table.PrimaryKey = new DataColumn[] { column };
foreach( Message message in list.GetUnderlyingValues() ) {
DataRow row = table.NewRow();
row[ "Action" ] = message.Action;
row[ "Message ID" ] = message.Id;
row[ "From" ] = message.From;
row[ "Sent" ] = message.DateSent;
row[ "Subject" ] = message.Subject;
row[ "Why Held" ] = message.WhyHeld;
table.Rows.Add( row );
}
// Preserve sort on rerendering.
if( control.DataSource != null )
table.DefaultView.Sort = ((DataSet) control.DataSource).Tables[ "HeldMessages" ].DefaultView.Sort;
DataSet dset = new DataSet();
dset.Tables.Add( table );
control.SetDataBinding( dset, "HeldMessages" );
}
示例5: TestSetDataBinding
public void TestSetDataBinding ()
{
DataGrid dg = new DataGrid ();
DataSet ds = new DataSet ("DataSet");
DataTable dt = new DataTable ("DataTable");
ds.Tables.Add (dt);
dg.SetDataBinding (ds, "DataTable");
}
示例6: AddGrid
// called by the method above
void AddGrid(DataTable dt)
{
DataGrid dataGrid = new DataGrid();
// Due to a bug in the grid control, we must add the grid to the tabpage before assigning a datasource.
// This bug was introduced in Beta 1, was fixed for Beta 2, then reared its ugly head again in RTM.
TabPage tabPage = new TabPage ("Result Set " + (tabControl.TabCount).ToString());
tabPage.Controls.Add (dataGrid);
tabControl.TabPages.Add (tabPage);
dataGrid.Dock = System.Windows.Forms.DockStyle.Fill;
dataGrid.CaptionVisible = false;
dataGrid.ReadOnly = true;
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = dt.TableName;
dataGrid.TableStyles.Clear();
dataGrid.TableStyles.Add (ts);
dataGrid.SetDataBinding (dt, "");
// The auto sizing feature below is no longer supported in RTM.
// dataGrid.PreferredColumnWidth = -1;
// Instead we'll have to size each column manually.
// A graphics object is required to measure text so we can size the grid columns correctly
System.Drawing.Graphics g = CreateGraphics();
// For each column, determine the largest visible text string, and use that to size the column
// We'll be measuring text for each row that's visible in the grid
int maxRows = Math.Min (dataGrid.VisibleRowCount, dt.Rows.Count);
GridColumnStylesCollection cols = ts.GridColumnStyles;
const int margin = 6; // allow 6 pixels per column, for grid lines and some white space
int colNum = 0;
if (cols.Count == 1)
cols[0].Width = dataGrid.Width;
else
foreach (DataGridColumnStyle col in cols)
{
int maxWidth = (int) g.MeasureString (col.HeaderText, dataGrid.Font).Width+ margin;
for (int row = 0; row < maxRows; row++)
{
string s = dt.Rows [row] [colNum, DataRowVersion.Current].ToString();
int length = (int) g.MeasureString (s, dataGrid.Font).Width+ margin;
maxWidth = Math.Max (maxWidth, length);
}
// Assign length of longest string to the column width, but don't exceed width of actual grid.
col.Width =Math.Min (dataGrid.Width, maxWidth);
colNum++;
}
g.Dispose();
// Set datetime columns to show the time as well as the date
colNum = 0;
foreach (DataGridColumnStyle col in cols)
{
DataGridTextBoxColumn textCol = col as DataGridTextBoxColumn;
if (textCol != null && dt.Columns [colNum].DataType == typeof (DateTime))
// Display the date in short format (ie using numbers), and the time in long
// format (ie including seconds). This is done using the 'G' format string.
textCol.Format = "G";
colNum++;
}
}