热门关键字:  PHP  Cisco  seo  网络广告 虚拟主机 中文域名

DataGrid相关知识总结(收集)

来源:搜站长搜集 作者:未知 时间:2005-10-23 点击:



/* 计算tables.对每个客户,创建DataRow变量 */
DataRow newRow1;

// 添加记录到 Customers Table.
for(int i = 1; i < 4; i++)
{
newRow1 = tCust.NewRow();
newRow1["custID"] = (100*i).ToString();
tCust.Rows.Add(newRow1);
}

tCust.Rows[0]["custName"] = "【孟宪会之精彩世界】";
tCust.Rows[1]["custName"] = "net_lover";
tCust.Rows[2]["custName"] = "http://xml.sz.luohuedu.net/";


tCust.Rows[0]["custCity"] = "北京";
tCust.Rows[1]["custCity"] = "上海";
tCust.Rows[2]["custCity"] = "河南";
}

private void AddCustomDataTableStyle()
{
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "Customers";
// 设置属性
ts1.AlternatingBackColor = Color.LightGray;

// 添加Textbox列样式,以便我们捕捉鼠标事件
DataGridTextBoxColumn TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "custID";
TextCol.HeaderText = "序号";
TextCol.Width = 100;

//添加事件处理器
TextCol.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler);
TextCol.TextBox.DoubleClick += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "custName";
TextCol.HeaderText = "姓名";
TextCol.Width = 100;
//添加事件处理器
TextCol.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler);
TextCol.TextBox.DoubleClick += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "custCity";
TextCol.HeaderText = "地址";
TextCol.Width = 100;
//添加事件处理器
TextCol.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler);
TextCol.TextBox.DoubleClick += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

dataGrid1.TableStyles.Add(ts1);

}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Info;
this.dataGrid1.CaptionForeColor = System.Drawing.SystemColors.WindowText;
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(11, 9);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(368, 144);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dataGrid1_MouseDown);
//
// label1
//
this.label1.Location = new System.Drawing.Point(4, 166);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(383, 23);
this.label1.TabIndex = 1;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label1.Click += new System.EventHandler(this.Form1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(387, 201);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1,
this.dataGrid1});
this.Name = "Form1";
this.Text = "鼠标双击事件的例子";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void TextBoxDoubleClickHandler(object sender, EventArgs e)
{
MessageBox.Show("双击事件发生。鼠标双击到的值:"+((TextBox)sender).Text.ToString());
}

private void TextBoxMouseDownHandler(object sender, MouseEventArgs e)
{
if(DateTime.Now < gridMouseDownTime.AddMilliseconds(SystemInformation.DoubleClickTime))
{
MessageBox.Show("双击事件发生。鼠标双击到的值:"+((TextBox)sender).Text.ToString());
}
label1.Text = "TextBox 鼠标按下了。 ";
}

private void dataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
gridMouseDownTime = DateTime.Now;
label1.Text = "DataGrid1 鼠标按下了。 ";
}

private void Form1_Click(object sender, System.EventArgs e)
{
label1.Text="";
}
private void label1_Click(object sender, System.EventArgs e)
{
label1.Text="";
}
}
}



namespace DataGridDoubleClick
{
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private DataSet myDataSet;
DateTime gridMouseDownTime;
private System.Windows.Forms.Label label1;

private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
gridMouseDownTime = DateTime.Now;
SetUp();
}

private void SetUp()
{
// 用2个Table和1和Relation创建DataSet
MakeDataSet();
// 数据绑定
dataGrid1.SetDataBinding(myDataSet, "Customers");

//添加样式
AddCustomDataTableStyle();
}

private void MakeDataSet()
{
// 创建DataSet.
myDataSet = new DataSet("myDataSet");

// 创建2个DataTables.
DataTable tCust = new DataTable("Customers");

// 创建两个列,并添加到第一个表
DataColumn cCustID = new DataColumn("custID");
DataColumn cCustName = new DataColumn("custName");
DataColumn cCurrent = new DataColumn("custCity");
tCust.Columns.Add(cCustID);
tCust.Columns.Add(cCustName);
tCust.Columns.Add(cCurrent);

// 把tables添加到DataSet.
myDataSet.Tables.Add(tCust);


/* 计算tables.对每个客户,创建DataRow变量 */
DataRow newRow1;

// 添加记录到 Customers Table.
for(int i = 1; i < 4; i++)
{
newRow1 = tCust.NewRow();
newRow1["custID"] = (100*i).ToString();
tCust.Rows.Add(newRow1);
}

tCust.Rows[0]["custName"] = "【孟宪会之精彩世界】";
tCust.Rows[1]["custName"] = "net_lover";
tCust.Rows[2]["custName"] = "http://xml.sz.luohuedu.net/";


tCust.Rows[0]["custCity"] = "北京";
tCust.Rows[1]["custCity"] = "上海";
tCust.Rows[2]["custCity"] = "河南";
}

private void AddCustomDataTableStyle()
{
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "Customers";
// 设置属性
ts1.AlternatingBackColor = Color.LightGray;

// 添加Textbox列样式,以便我们捕捉鼠标事件
DataGridTextBoxColumn TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "custID";
TextCol.HeaderText = "序号";
TextCol.Width = 100;

//添加事件处理器
TextCol.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler);
TextCol.TextBox.DoubleClick += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "custName";
TextCol.HeaderText = "姓名";
TextCol.Width = 100;
//添加事件处理器
TextCol.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler);
TextCol.TextBox.DoubleClick += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "custCity";
TextCol.HeaderText = "地址";
TextCol.Width = 100;
//添加事件处理器
TextCol.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler);
TextCol.TextBox.DoubleClick += new EventHandler(TextBoxDoubleClickHandler);
ts1.GridColumnStyles.Add(TextCol);

dataGrid1.TableStyles.Add(ts1);

}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Info;
this.dataGrid1.CaptionForeColor = System.Drawing.SystemColors.WindowText;
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(11, 9);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(368, 144);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dataGrid1_MouseDown);
//
// label1
//
this.label1.Location = new System.Drawing.Point(4, 166);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(383, 23);
this.label1.TabIndex = 1;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label1.Click += new System.EventHandler(this.Form1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(387, 201);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1,
this.dataGrid1});
this.Name = "Form1";
this.Text = "鼠标双击事件的例子";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void TextBoxDoubleClickHandler(object sender, EventArgs e)
{
MessageBox.Show("双击事件发生。鼠标双击到的值:"+((TextBox)sender).Text.ToString());
}

private void TextBoxMouseDownHandler(object sender, MouseEventArgs e)
{
if(DateTime.Now < gridMouseDownTime.AddMilliseconds(SystemInformation.DoubleClickTime))
{
MessageBox.Show("双击事件发生。鼠标双击到的值:"+((TextBox)sender).Text.ToString());
}
label1.Text = "TextBox 鼠标按下了。 ";
}

private void dataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
gridMouseDownTime = DateTime.Now;
label1.Text = "DataGrid1 鼠标按下了。 ";
}

private void Form1_Click(object sender, System.EventArgs e)
{
label1.Text="";
}
private void label1_Click(object sender, System.EventArgs e)
{
label1.Text="";
}
}
}


主  题: 在C#(winform)中如何设置datagrid某一行的背景色,或字体的颜色啊?高手救命!!


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace DataGridCellFormatting
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form2()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 56);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(536, 296);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dataGrid1_Navigate);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(560, 389);
this.Controls.Add(this.dataGrid1);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion


private void FormatGridCells(object sender, DataGridFormatCellEventArgs e)
{
//color row 1 red
if(e.Row == 0)
e.BackBrush = Brushes.Red;
if(e.Row == 1)
e.BackBrush = Brushes.Red;
if(e.Row == 2)
e.BackBrush = Brushes.Red;
if(e.Row == 3)
e.BackBrush = Brushes.Red;

//color column 4 blue
//if(e.Column == 4)
//e.BackBrush = Brushes.Blue;
//
////set font of some cells to bold
//if( (e.Row + e.Column) % 5 == 0 )
//e.TextFont = new Font(e.TextFont.Name, e.TextFont.Size, FontStyle.Bold);
//
////set textcolor of some cells to blue
//if( (e.Row + e.Column) % 8 == 0 )
//e.ForeBrush = Brushes.DodgerBlue;
//
////set font of some cells to bold, underline, italic with white text on green background
//if( (e.Row + e.Column) % 9 == 0 )
//{
//e.TextFont = new Font(e.TextFont.Name, e.TextFont.Size, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline);
//e.ForeBrush = Brushes.White;
//e.BackBrush = Brushes.Green;
//}


}

private DataTable SomeDataTable()
{
DataTable dt = new DataTable("MyTable");

//add some columns
int nCols = 10;
for(int j = 0; j < nCols; ++j)
dt.Columns.Add(new DataColumn(string.Format("col{0}", j), typeof(string)));

//add some rows
int nRows = 40;
for(int i = 0; i < nRows; ++i)
{
DataRow dr = dt.NewRow();
for(int j = 0; j < nCols; ++j)
dr[j] = string.Format("row {0} col {1}", i, j);
dt.Rows.Add(dr);
}

dt.DefaultView.AllowNew = false;//turn off append row
return dt;
}

private void AddCellFormattingColumnStyles(DataGrid grid, FormatCellEventHandler handler)
{
DataGridTableStyle ts = new DataGridTableStyle();

DataTable dt = (DataTable) grid.DataSource;

ts.MappingName = dt.TableName;

for(int j = 0; j < dt.Columns.Count; ++j)
{
DataGridFormattableTextBoxColumn cs = new DataGridFormattableTextBoxColumn(j);
cs.MappingName = dt.Columns[j].ColumnName;
cs.HeaderText = dt.Columns[j].ColumnName;
cs.SetCellFormat += handler;
ts.GridColumnStyles.Add(cs);
}

grid.TableStyles.Clear();
grid.TableStyles.Add(ts);

}
private void dataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
{

}

private void Form2_Load(object sender, System.EventArgs e)
{
this.dataGrid1.DataSource = SomeDataTable();

AddCellFormattingColumnStyles(this.dataGrid1, new FormatCellEventHandler(FormatGridCells));
}

public delegate void FormatCellEventHandler(object sender, DataGridFormatCellEventArgs e);

public class DataGridFormatCellEventArgs : EventArgs
{
private int _column;
private int _row;
private Font _font;
private Brush _backBrush;
private Brush _foreBrush;
private bool _useBaseClassDrawing;


public DataGridFormatCellEventArgs(int row, int col, Font font1, Brush backBrush, Brush foreBrush)
{
_row = row;
_column = col;
_font = font1;
_backBrush = backBrush;
_foreBrush = foreBrush;
_useBaseClassDrawing = false;
}

public int Column
{
get{ return _column;}
set{ _column = value;}
}
public int Row
{
get{ return _row;}
set{ _row = value;}
}
public Font TextFont
{
get{ return _font;}
set{ _font = value;}
}

public Brush BackBrush
{
get{ return _backBrush;}
set{ _backBrush = value;}
}
public Brush ForeBrush
{
get{ return _foreBrush;}
set{ _foreBrush = value;}
}
public bool UseBaseClassDrawing
{
get{ return _useBaseClassDrawing;}
set{ _useBaseClassDrawing = value;}
}
}

public class DataGridFormattableTextBoxColumn : DataGridTextBoxColumn
{
//in your handler, set the EnableValue to true or false, depending upon the row & col
public event FormatCellEventHandler SetCellFormat;

private int _col;

public DataGridFormattableTextBoxColumn(int col)
{
_col = col;
}

protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
{
DataGridFormatCellEventArgs e = new DataGridFormatCellEventArgs(rowNum, this._col, this.DataGridTableStyle.DataGrid.Font, backBrush, foreBrush);
if(SetCellFormat != null)
{
SetCellFormat(this, e);
}
if(e.UseBaseClassDrawing)
base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
else
{
g.FillRectangle(e.BackBrush, bounds);
g.DrawString(this.GetColumnValueAtRow(source, rowNum).ToString(), e.TextFont, e.ForeBrush, bounds.X, bounds.Y);
}
if(e.TextFont != this.DataGridTableStyle.DataGrid.Font)
e.TextFont.Dispose();
}

protected override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
{
//comment to make cells unable to become editable
base.Edit(source, rowNum, bounds, readOnly, instantText, cellIsVisible);
}

}
}
}


只需要改变FormatGridCells中的行就行了


主  题: 如何让WINFORM的DATAGRID控件的列有的为只读属性,有的不是只读属性

1、手工:Datagrid->属性->TableStyles->GridCoumnStyles

2、代码:this.dataGrid1.TableStyles["tablename"].GridColumnStyles["ID"].ReadOnly = true;



this.dataGrid1.TableStyles["tablename"].GridColumnStyles["ID"].ReadOnly = true;


显示和隐藏DataGrid中的列

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ShowHideCols.aspx.vb"
Inherits="aspxWeb.ShowHideCols"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>ShowHideCols</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button ID="btnShow" Text="Show Details" OnClick="ShowDetails" Runat="server" />
<asp:Button ID="btnHide" Text="Hide Details" OnClick="HideDetails" Runat="server" />
<asp:DataGrid ID="dtgCusts" Runat="server" AutoGenerateColumns="False"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" BackColor="White"
CellPadding="3" GridLines="Vertical">
<Columns>
<asp:BoundColumn DataField="Title" />
<asp:BoundColumn DataField="id" Visible="False" />
<asp:BoundColumn DataField="CreateDate" DataFormatString="{0:yyyy-MM-dd HH:mm:ss}"
Visible="False" />
<asp:EditCommandColumn EditText="Edit" HeaderText="Edit" Visible="False" />
</Columns>
<AlternatingItemStyle BackColor="#DCDCDC" />
<ItemStyle ForeColor="Black" BackColor="#EEEEEE" />
<headerStyle Font-Bold="True" ForeColor="White" BackColor="#000084" />
</asp:DataGrid>
</form>
</body>
</HTML>

Imports System.Data
Imports System.Data.OleDb

Public Class ShowHideCols
Inherits System.Web.UI.Page
Protected WithEvents btnShow As System.Web.UI.WebControls.Button
Protected WithEvents btnHide As System.Web.UI.WebControls.Button
Protected WithEvents dtgCusts As System.Web.UI.WebControls.DataGrid

#Region " Web 窗体设计器生成的代码 "

'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs)_
Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)_
Handles MyBase.Load
'在此处放置初始化页的用户代码
btnShow.Text = "显示列"
btnHide.Text = "隐藏列"
dtgCusts.Columns(1).HeaderText = ""
dtgCusts.Columns(0).HeaderText = "标题"
dtgCusts.Columns(2).HeaderText = "发布日期"
dtgCusts.Columns(3).HeaderText = "编辑"
If Not IsPostBack Then
BindTheData()
End If
End Sub

Sub BindTheData()
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
objConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
+ Server.MapPath("Test.mdb"))
Dim strSql As String
strSql = "SELECT Top 10 id,Title,CreateDate FROM Document"
objCmd = New OleDbCommand(strSql, objConn)
objConn.Open()
dtgCusts.DataSource = objCmd.ExecuteReader()
dtgCusts.DataBind()
objConn.Close()
objConn.Dispose()
End Sub
Sub ShowDetails(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim intCounter As Integer
For intCounter = 1 To dtgCusts.Columns.Count - 1
dtgCusts.Columns(intCounter).Visible = True
Next
End Sub

Sub HideDetails(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim intCounter As Integer
For intCounter = 1 To dtgCusts.Columns.Count - 1
dtgCusts.Columns(intCounter).Visible = False
Next
End Sub

End Class



主  题: 请教在DataGridView中怎样生成自适应的列宽?
你可以用下面的方法实现:
private void gridView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
int a=e.X/colKeyWords.Width;
int b=(e.Y+10)/colKeyWords.Width-3;
if(a>=0 && b>=0 && a<dataSet11.Tables["BugMan"].Columns.Count && b<dataSet11.Tables["BugMan"].Rows.Count)
toolTipController1.SetToolTip(gridControl1,dataSet11.Tables["BugMan"].Rows[b].ItemArray[a].ToString());
}
我用的是tooltip,colkeywords.width是某一个列的长度


最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
赞助商连接