如何让DataGrid自动选定行? 在WinForm中如何在选定一个单元格的时候让它自动选定一行 我试了好久都没搞好!求求高手啦! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 How can I select the entire row when the user clicks on a cell in the row?http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q689q id=int.Parse(this.SuperGrid1.SelectedItem .Cells[列数].Text.ToString().Trim()); DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; public class DataGrid:DataGridView { public DataGrid() { this.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; this.MultiSelect = false; this.ShowCellToolTips = true; this.AllowDrop = false; this.EditMode = DataGridViewEditMode.EditProgrammatically; this.AllowUserToAddRows = false; this.AllowUserToDeleteRows = false; this.AllowUserToOrderColumns = true; this.AllowUserToResizeColumns = true; this.AllowUserToResizeRows = true; DataGridViewCellStyle loAlterStyle = new DataGridViewCellStyle(); loAlterStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; loAlterStyle.BackColor = Color.FromArgb(192, 255, 255); loAlterStyle.ForeColor = Color.Black; loAlterStyle.WrapMode = DataGridViewTriState.NotSet; this.AlternatingRowsDefaultCellStyle = loAlterStyle; this.BackgroundColor = Color.LightYellow; this.BorderStyle = BorderStyle.FixedSingle; this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; this.CellBorderStyle = DataGridViewCellBorderStyle.SingleVertical; this.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; this.ColumnHeadersVisible = true; this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing; this.ColumnHeadersHeight = 20; DataGridViewCellStyle loHeaderStyle = new DataGridViewCellStyle(); loHeaderStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; loHeaderStyle.BackColor = Color.FromArgb(192, 255, 255); loHeaderStyle.ForeColor = Color.Black; loHeaderStyle.SelectionBackColor = Color.FromArgb(0, 0, 64); loHeaderStyle.SelectionForeColor = Color.White; loAlterStyle.WrapMode = DataGridViewTriState.NotSet; this.ColumnHeadersDefaultCellStyle = loHeaderStyle; this.GridColor = Color.FromArgb(128, 255, 255); this.SelectionMode = DataGridViewSelectionMode.FullRowSelect; this.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; this.ReadOnly = true; this.EditMode = DataGridViewEditMode.EditOnF2; this.RowHeadersVisible = false; this.RowHeadersWidth = 5; //this.AlternatingRowsDefaultCellStyle.BackColor = Color.; } protected override void OnRowPrePaint(DataGridViewRowPrePaintEventArgs e) { //去除选中Cell时的虚框 e.PaintParts = e.PaintParts ^ DataGridViewPaintParts.Focus; base.OnRowPrePaint(e); } protected override void OnCellMouseEnter(DataGridViewCellEventArgs e) { if (e.ColumnIndex > -1 && e.RowIndex > -1) { string lcDataStr = this.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); this.Rows[e.RowIndex].Cells[e.ColumnIndex].ToolTipText = lcDataStr; } base.OnCellMouseEnter(e); } protected override void OnCellMouseClick(DataGridViewCellMouseEventArgs e) { //右键点击时把当前内容拷贝到粘贴板 if (e.Button == MouseButtons.Right) { if (e.ColumnIndex > -1 && e.RowIndex > -1) { string lcDataStr = this.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); Clipboard.SetText(lcDataStr); } } base.OnCellMouseClick(e); } } 关于datagridview 的小问题哦 各位大虾求教解析XML,谢谢 Proccess.Start启动程序时,怎样显示到指定的显示器(屏幕)上? .NET下,用C#语言如何实现IP伪装,目的在于IP不被网站查封,高手请赐教!!!! 如何获取顶层窗口 一个c++如何转成c#的简单问题? 有ASP.NET C#的程序员吗 ? 一个网站项目 5天 全职 4000元 有谁有兴趣做? 请教一个字符串的问题 如何分割和在网络上传输文件 新人求助 关于线程问题..新人,请各位大哥大姐帮忙 模拟鼠标键盘自动提交的问题
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q689q
{ public DataGrid()
{
this.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
this.MultiSelect = false;
this.ShowCellToolTips = true; this.AllowDrop = false;
this.EditMode = DataGridViewEditMode.EditProgrammatically;
this.AllowUserToAddRows = false;
this.AllowUserToDeleteRows = false;
this.AllowUserToOrderColumns = true;
this.AllowUserToResizeColumns = true;
this.AllowUserToResizeRows = true; DataGridViewCellStyle loAlterStyle = new DataGridViewCellStyle();
loAlterStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
loAlterStyle.BackColor = Color.FromArgb(192, 255, 255);
loAlterStyle.ForeColor = Color.Black;
loAlterStyle.WrapMode = DataGridViewTriState.NotSet;
this.AlternatingRowsDefaultCellStyle = loAlterStyle; this.BackgroundColor = Color.LightYellow;
this.BorderStyle = BorderStyle.FixedSingle;
this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
this.CellBorderStyle = DataGridViewCellBorderStyle.SingleVertical;
this.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
this.ColumnHeadersVisible = true;
this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
this.ColumnHeadersHeight = 20;
DataGridViewCellStyle loHeaderStyle = new DataGridViewCellStyle(); loHeaderStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
loHeaderStyle.BackColor = Color.FromArgb(192, 255, 255);
loHeaderStyle.ForeColor = Color.Black;
loHeaderStyle.SelectionBackColor = Color.FromArgb(0, 0, 64);
loHeaderStyle.SelectionForeColor = Color.White;
loAlterStyle.WrapMode = DataGridViewTriState.NotSet;
this.ColumnHeadersDefaultCellStyle = loHeaderStyle; this.GridColor = Color.FromArgb(128, 255, 255);
this.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
this.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
this.ReadOnly = true;
this.EditMode = DataGridViewEditMode.EditOnF2;
this.RowHeadersVisible = false;
this.RowHeadersWidth = 5;
//this.AlternatingRowsDefaultCellStyle.BackColor = Color.;
} protected override void OnRowPrePaint(DataGridViewRowPrePaintEventArgs e)
{
//去除选中Cell时的虚框
e.PaintParts = e.PaintParts ^ DataGridViewPaintParts.Focus;
base.OnRowPrePaint(e);
} protected override void OnCellMouseEnter(DataGridViewCellEventArgs e)
{
if (e.ColumnIndex > -1 && e.RowIndex > -1)
{
string lcDataStr = this.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
this.Rows[e.RowIndex].Cells[e.ColumnIndex].ToolTipText = lcDataStr;
}
base.OnCellMouseEnter(e);
} protected override void OnCellMouseClick(DataGridViewCellMouseEventArgs e)
{
//右键点击时把当前内容拷贝到粘贴板
if (e.Button == MouseButtons.Right)
{
if (e.ColumnIndex > -1 && e.RowIndex > -1)
{
string lcDataStr = this.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
Clipboard.SetText(lcDataStr);
}
}
base.OnCellMouseClick(e);
}
}