本文整理匯總了C#中System.Windows.Forms.DataGridView.BorderStyle屬性的典型用法代碼示例。如果您正苦於以下問題:C# DataGridView.BorderStyle屬性的具體用法?C# DataGridView.BorderStyle怎麽用?C# DataGridView.BorderStyle使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Windows.Forms.DataGridView
的用法示例。
在下文中一共展示了DataGridView.BorderStyle屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DataGridView
//引入命名空間
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Drawing;
public class Form1 : System.Windows.Forms.Form
{
private DataGridView dataGridView1 = new DataGridView();
private BindingSource bindingSource1 = new BindingSource();
public Form1()
{
dataGridView1.Dock = DockStyle.Fill;
this.Controls.Add(dataGridView1);
InitializeDataGridView();
}
private void InitializeDataGridView()
{
try
{
// Set up the DataGridView.
dataGridView1.Dock = DockStyle.Fill;
// Automatically generate the DataGridView columns.
dataGridView1.AutoGenerateColumns = true;
// Set up the data source.
bindingSource1.DataSource = GetData("Select * From Products");
dataGridView1.DataSource = bindingSource1;
// Automatically resize the visible rows.
dataGridView1.AutoSizeRowsMode =
DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
// Set the DataGridView control's border.
dataGridView1.BorderStyle = BorderStyle.Fixed3D;
// Put the cells in edit mode when user enters them.
dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
}
catch (SqlException)
{
MessageBox.Show("To run this sample replace connection.ConnectionString" +
" with a valid connection string to a Northwind" +
" database accessible to your system.", "ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
System.Threading.Thread.CurrentThread.Abort();
}
}
private static DataTable GetData(string sqlCommand)
{
string connectionString = "Integrated Security=SSPI;" +
"Persist Security Info=False;" +
"Initial Catalog=Northwind;Data Source=localhost";
SqlConnection northwindConnection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(sqlCommand, northwindConnection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = command;
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
adapter.Fill(table);
return table;
}
[STAThreadAttribute()]
public static void Main()
{
Application.Run(new Form1());
}
}