本文整理汇总了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());
}
}