datagridview的常见属性,散分了 datagridview的常见属性及实现代码;多多益善,最好详细的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://msdn.microsoft.com/zh-tw/default.aspx然後在裏面搜索datagridview,你就能找到你要的東西了 知道一个datasource足够,剩下的查msdn就行了 备注DataGridView 控件提供用来显示数据的可自定义表。使用 DataGridView 类,可以通过使用 DefaultCellStyle、ColumnHeadersDefaultCellStyle、CellBorderStyle 和 GridColor 等属性对单元格、行、列和边框进行自定义。有关更多信息,请参见 Windows 窗体 DataGridView 控件中的基本格式设置和样式设置。可以使用 DataGridView 控件来显示有基础数据源或没有基础数据源的数据。如果没有指定数据源,可以创建包含数据的列和行,并将它们直接添加到 DataGridView。或者,可以设置 DataSource 和 DataMember 属性,以便将 DataGridView 绑定到数据源,并自动用数据填充该控件。有关更多信息,请参见在 Windows 窗体 DataGridView 控件中显示数据。在处理大量数据时,可以将 VirtualMode 属性设置为 true,以便显示可用数据的子集。虚拟模式要求实现用来填充 DataGridView 控件的数据缓存。有关更多信息,请参见 Windows 窗体 DataGridView 控件中的数据显示模式。有关 DataGridView 控件中可用功能的其他信息,请参见 DataGridView 控件(Windows 窗体)。 虽然 DataGridView 控件替代了以前版本的 DataGrid 控件并增加了功能,但是为了实现向后兼容并考虑到将来的使用(如果您选择的话),仍然保留了 DataGrid 控件。有关更多信息,请参见 Windows 窗体 DataGridView 控件和 DataGrid 控件之间的区别。示例下面的代码示例演示如何初始化一个未绑定的 DataGridView。要运行此示例,请将下面的代码粘贴到一个窗体中,该窗体包含一个名为 dataGridView1 的 DataGridView 以及三个名称分别为 addNewRowButton、deleteRowButton 和 ledgerStyleButton 的按钮。从窗体的构造函数或 Load 事件处理程序中调用 SetUpDataGridView 和 PopulateDataGridView 方法。确保所有事件都与其事件处理程序关联。private void ledgerStyleButton_Click(object sender, System.EventArgs e){ // Create a new cell style. DataGridViewCellStyle style = new DataGridViewCellStyle(); { style.BackColor = Color.Beige; style.ForeColor = Color.Brown; style.Font = new Font("Verdana", 8); } // Apply the style as the default cell style. dataGridView1.AlternatingRowsDefaultCellStyle = style; ledgerStyleButton.Enabled = false;}private void SetUpDataGridView(){ this.Controls.Add(dataGridView1); dataGridView1.ColumnCount = 5; DataGridViewCellStyle style = dataGridView1.ColumnHeadersDefaultCellStyle; style.BackColor = Color.Navy; style.ForeColor = Color.White; style.Font = new Font(dataGridView1.Font, FontStyle.Bold); dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter; dataGridView1.Name = "dataGridView1"; dataGridView1.Location = new Point(8, 8); dataGridView1.Size = new Size(500, 300); dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders; dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised; dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single; dataGridView1.GridColor = SystemColors.ActiveBorder; dataGridView1.RowHeadersVisible = false; dataGridView1.Columns[0].Name = "Release Date"; dataGridView1.Columns[1].Name = "Track"; dataGridView1.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridView1.Columns[2].Name = "Title"; dataGridView1.Columns[3].Name = "Artist"; dataGridView1.Columns[4].Name = "Album"; // Make the font italic for row four. dataGridView1.Columns[4].DefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Italic); dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.MultiSelect = false; dataGridView1.BackgroundColor = Color.Honeydew; dataGridView1.Dock = DockStyle.Fill; dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting); dataGridView1.CellParsing += new DataGridViewCellParsingEventHandler(dataGridView1_CellParsing); addNewRowButton.Click += new EventHandler(addNewRowButton_Click); deleteRowButton.Click += new EventHandler(deleteRowButton_Click); ledgerStyleButton.Click += new EventHandler(ledgerStyleButton_Click); dataGridView1.CellValidating += new DataGridViewCellValidatingEventHandler(dataGridView1_CellValidating);}private void PopulateDataGridView(){ // Create the string array for each row of data. string[] row0 = { "11/22/1968", "29", "Revolution 9", "Beatles", "The Beatles [White Album]" }; string[] row1 = { "4/4/1960", "6", "Fools Rush In", "Frank Sinatra", "Nice 'N' Easy" }; string[] row2 = { "11/11/1971", "1", "One of These Days", "Pink Floyd", "Meddle" }; string[] row3 = { "4/4/1988", "7", "Where Is My Mind?", "Pixies", "Surfer Rosa" }; string[] row4 = { "5/1981", "9", "Can't Find My Mind", "Cramps", "Psychedelic Jungle" }; string[] row5 = { "6/10/2003", "13", "Scatterbrain. (As Dead As Leaves.)", "Radiohead", "Hail to the Thief" }; string[] row6 = { "6/30/1992", "3", "Dress", "P J Harvey", "Dry" }; // Add a row for each string array. { DataGridViewRowCollection rows = this.dataGridView1.Rows; rows.Add(row0); rows.Add(row1); rows.Add(row2); rows.Add(row3); rows.Add(row4); rows.Add(row5); rows.Add(row6); } // Change the order the columns are displayed. { DataGridViewColumnCollection columns = this.dataGridView1.Columns; columns[0].DisplayIndex = 3; columns[1].DisplayIndex = 4; columns[2].DisplayIndex = 0; columns[3].DisplayIndex = 1; columns[4].DisplayIndex = 2; }} msdn最全面,操作参考 LZ 应该是学习C#的新手吧,建议多查看MSDN, 只要输入DataGridView就可以查看它的属性,方法,事件随时可以查阅另外 楼主 可以安装VS是附带安装MSDN 帮助文档 是在不行就网络版的MSDN的也行 LZ 应该是学习C#的新手吧,建议多查看MSDN, 只要输入DataGridView就可以查看它的属性,方法,事件随时可以查阅另外 楼主 可以安装VS是附带安装MSDN 帮助文档 是在不行就网络版的MSDN的也行 LZ 应该是学习C#的新手吧,建议多查看MSDN, 只要输入DataGridView就可以查看它的属性,方法,事件随时可以查阅另外 楼主 可以安装VS是附带安装MSDN 帮助文档 是在不行就网络版的MSDN的也行 MSDN,上面有实例的,照着做一两个例子就会了 要了解一个控件的具体属性,msdn无疑是最好的老师 MSDN .net framework 下的datagridview类,打开就看见了,属性和方法的列表都可见,楼主要多多利用一资源, 各位大虾!dataGridView的每个单元格,可以显示图片吗? 看看HELP文件吧,多看见次就常见了 MSDN上有我也知道但谁有列出的常见的总结,谁要再说这,一分不给!!!!!! 工厂模式使用问题 winfrom实现方向键(上下左右)控制焦点 [WinAPI]如何将VB中的一个API调用程序转换为C#语句 请问C#中如何用Read()读取一个整数,帮忙看一下这个小程序! c#的窗体停靠技术是如何实现的? 关于读写TXT文件的问题,见者有分 webform中的Datagrid模板列问题,请各位高人相助 如何实现163邮箱下载Excel弹出新页面的效果 一个关于C#递归的算法,求各路大神解答 日期修改小时分秒 请问如何体验出使用接口调用的灵活性? list转intptr有人知道么
然後在裏面搜索datagridview,你就能找到你要的東西了
DataGridView 控件提供用来显示数据的可自定义表。使用 DataGridView 类,可以通过使用 DefaultCellStyle、ColumnHeadersDefaultCellStyle、CellBorderStyle 和 GridColor 等属性对单元格、行、列和边框进行自定义。有关更多信息,请参见 Windows 窗体 DataGridView 控件中的基本格式设置和样式设置。可以使用 DataGridView 控件来显示有基础数据源或没有基础数据源的数据。如果没有指定数据源,可以创建包含数据的列和行,并将它们直接添加到 DataGridView。或者,可以设置 DataSource 和 DataMember 属性,以便将 DataGridView 绑定到数据源,并自动用数据填充该控件。有关更多信息,请参见在 Windows 窗体 DataGridView 控件中显示数据。在处理大量数据时,可以将 VirtualMode 属性设置为 true,以便显示可用数据的子集。虚拟模式要求实现用来填充 DataGridView 控件的数据缓存。有关更多信息,请参见 Windows 窗体 DataGridView 控件中的数据显示模式。有关 DataGridView 控件中可用功能的其他信息,请参见 DataGridView 控件(Windows 窗体)。 虽然 DataGridView 控件替代了以前版本的 DataGrid 控件并增加了功能,但是为了实现向后兼容并考虑到将来的使用(如果您选择的话),仍然保留了 DataGrid 控件。有关更多信息,请参见 Windows 窗体 DataGridView 控件和 DataGrid 控件之间的区别。示例
下面的代码示例演示如何初始化一个未绑定的 DataGridView。要运行此示例,请将下面的代码粘贴到一个窗体中,该窗体包含一个名为 dataGridView1 的 DataGridView 以及三个名称分别为 addNewRowButton、deleteRowButton 和 ledgerStyleButton 的按钮。从窗体的构造函数或 Load 事件处理程序中调用 SetUpDataGridView 和 PopulateDataGridView 方法。确保所有事件都与其事件处理程序关联。
private void ledgerStyleButton_Click(object sender, System.EventArgs e)
{
// Create a new cell style.
DataGridViewCellStyle style = new DataGridViewCellStyle();
{
style.BackColor = Color.Beige;
style.ForeColor = Color.Brown;
style.Font = new Font("Verdana", 8);
} // Apply the style as the default cell style.
dataGridView1.AlternatingRowsDefaultCellStyle = style;
ledgerStyleButton.Enabled = false;
}private void SetUpDataGridView()
{
this.Controls.Add(dataGridView1);
dataGridView1.ColumnCount = 5;
DataGridViewCellStyle style =
dataGridView1.ColumnHeadersDefaultCellStyle;
style.BackColor = Color.Navy;
style.ForeColor = Color.White;
style.Font = new Font(dataGridView1.Font, FontStyle.Bold); dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
dataGridView1.Name = "dataGridView1";
dataGridView1.Location = new Point(8, 8);
dataGridView1.Size = new Size(500, 300);
dataGridView1.AutoSizeRowsMode =
DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
dataGridView1.ColumnHeadersBorderStyle =
DataGridViewHeaderBorderStyle.Raised;
dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
dataGridView1.GridColor = SystemColors.ActiveBorder;
dataGridView1.RowHeadersVisible = false; dataGridView1.Columns[0].Name = "Release Date";
dataGridView1.Columns[1].Name = "Track";
dataGridView1.Columns[1].DefaultCellStyle.Alignment =
DataGridViewContentAlignment.MiddleCenter;
dataGridView1.Columns[2].Name = "Title";
dataGridView1.Columns[3].Name = "Artist";
dataGridView1.Columns[4].Name = "Album"; // Make the font italic for row four.
dataGridView1.Columns[4].DefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Italic); dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.MultiSelect = false; dataGridView1.BackgroundColor = Color.Honeydew; dataGridView1.Dock = DockStyle.Fill; dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);
dataGridView1.CellParsing += new DataGridViewCellParsingEventHandler(dataGridView1_CellParsing);
addNewRowButton.Click += new EventHandler(addNewRowButton_Click);
deleteRowButton.Click += new EventHandler(deleteRowButton_Click);
ledgerStyleButton.Click += new EventHandler(ledgerStyleButton_Click);
dataGridView1.CellValidating += new DataGridViewCellValidatingEventHandler(dataGridView1_CellValidating);}private void PopulateDataGridView()
{ // Create the string array for each row of data.
string[] row0 = { "11/22/1968", "29", "Revolution 9", "Beatles", "The Beatles [White Album]" };
string[] row1 = { "4/4/1960", "6", "Fools Rush In", "Frank Sinatra", "Nice 'N' Easy" };
string[] row2 = { "11/11/1971", "1", "One of These Days", "Pink Floyd", "Meddle" };
string[] row3 = { "4/4/1988", "7", "Where Is My Mind?", "Pixies", "Surfer Rosa" };
string[] row4 = { "5/1981", "9", "Can't Find My Mind", "Cramps", "Psychedelic Jungle" };
string[] row5 = { "6/10/2003", "13", "Scatterbrain. (As Dead As Leaves.)", "Radiohead", "Hail to the Thief" };
string[] row6 = { "6/30/1992", "3", "Dress", "P J Harvey", "Dry" }; // Add a row for each string array.
{
DataGridViewRowCollection rows = this.dataGridView1.Rows;
rows.Add(row0);
rows.Add(row1);
rows.Add(row2);
rows.Add(row3);
rows.Add(row4);
rows.Add(row5);
rows.Add(row6);
} // Change the order the columns are displayed.
{
DataGridViewColumnCollection columns = this.dataGridView1.Columns;
columns[0].DisplayIndex = 3;
columns[1].DisplayIndex = 4;
columns[2].DisplayIndex = 0;
columns[3].DisplayIndex = 1;
columns[4].DisplayIndex = 2;
}
}
参考
另外 楼主 可以安装VS是附带安装MSDN 帮助文档 是在不行就网络版的MSDN的也行
另外 楼主 可以安装VS是附带安装MSDN 帮助文档 是在不行就网络版的MSDN的也行
另外 楼主 可以安装VS是附带安装MSDN 帮助文档 是在不行就网络版的MSDN的也行
dataGridView的每个单元格,可以显示图片吗?