(高分求救)winform下,datagrid在点击单元格时,如何让此单元格为不选中状态。

lorylovenn 2005-02-16 10:05:44
是这样的,我想左键点击选中一行,但是总是先选中一个单元格,并且此单元格先选中(为edit状态),我不想让它为edit状态。有何方法吗,谢谢大家了~
...全文
115 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lorylovenn 2005-02-16
  • 打赏
  • 举报
回复
linlinunix(铁匠)
用您说的方法的话,不能解决单元格的问题

我已经按照 hbxtlhx(踏雪寻岩)的代码 做到了~
谢谢各位了,马上结分~
linlinunix 2005-02-16
  • 打赏
  • 举报
回复

简单办法

增加 selectchange事件

datagrid.select(datagride.currentcell.rowindex);
代码不一定正确 但是 用这个思想没有问题 比较简单
lorylovenn 2005-02-16
  • 打赏
  • 举报
回复
谢了~呵呵
lorylovenn 2005-02-16
  • 打赏
  • 举报
回复
to : hbxtlhx(踏雪寻岩)
如何重写System.Windows.Forms.DataGridTextBoxColumn,能举个例子吗?
hedonister 2005-02-16
  • 打赏
  • 举报
回复
楼上的有道理
北京的雾霾天 2005-02-16
  • 打赏
  • 举报
回复
我有一段代码你可以参考一下:

public class TextColumnStyle : System.Windows.Forms.DataGridTextBoxColumn
{
private int nSelectedRowIndex;
public TextColumnStyle()
{
//
// TODO: 在此处添加构造函数逻辑
//
nSelectedRowIndex = -1;
}

protected override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
{
if (this.DataGridTableStyle.DataGrid.ReadOnly)
{
if(nSelectedRowIndex> -1 && nSelectedRowIndex< source.List.Count + 1)
{
this.DataGridTableStyle.DataGrid.UnSelect(nSelectedRowIndex);
}
this.DataGridTableStyle.DataGrid.Select(rowNum);
nSelectedRowIndex= rowNum;
}
else
{
base.Edit (source, rowNum, bounds, readOnly, instantText, cellIsVisible);
}
}
}

DataGridTableStyle tableStyle =null;
public void SetListDataEX(DataView dvw)
{
if (tableStyle==null)
{
tableStyle = new DataGridTableStyle();
tableStyle.MappingName =dvw.Table.TableName;
int numCols = dvw.Table.Columns.Count;
TextColumnStyle textColumn;
for (int i=0;i<dvw.Table.Columns.Count;i++)
{
textColumn = new TextColumnStyle((CurrencyManager)this.dataGrid1.BindingContext[dvw]);
textColumn.ReadOnly=false;
textColumn.NullText="";
textColumn.HeaderText = dvw.Table.Columns[i].Caption;
textColumn.MappingName = dvw.Table.Columns[i].ColumnName;
tableStyle.GridColumnStyles.Add(textColumn);
}

tableStyle.AllowSorting=false;
//tableStyle.RowHeadersVisible=false;
this.dataGrid1.TableStyles.Clear();
this.dataGrid1.TableStyles.Add(tableStyle);
}
this.dataGrid1.BeginInit();
this.dataGrid1.SetDataBinding(dvw,null);
this.dataGrid1.EndInit();
dvw.AllowDelete=true;
dvw.AllowEdit=true;
}
北京的雾霾天 2005-02-16
  • 打赏
  • 举报
回复
你要重写DataGrid的列来达到这个要求.比如重写如下这个类:
System.Windows.Forms.DataGridTextBoxColumn,
然后把这样的列加到一个新的DataGridTableStyle里来写制一个DataGrid.
liulxmooo 2005-02-16
  • 打赏
  • 举报
回复
up

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧