想在GridView查询出来的数据中单击一下任何一行就能选中此行.请教一下代码怎么写,该写在哪个地方
解决方案 »
- 对象的当前状态使该操作无效
- 并没有修改数据可以mytable.getChanges能获取到修改很奇怪
- 写好文件后,如何打开该文件所在目录啊?
- 用C#写的计算器,有注释
- (WFC)为什么运行svcutil.exe http://xxxxxx.com/Services.svc?wsdl不可以创建出配置文件?
- 为什么c#的OpenFileDialog读取的txt文件不能显示中文
- 如何让WebBrowser不下载图片动画声音等资源
- winform中如何记住共用工具条的状态
- 100分 新手求解决~~~~在线等~~~
- DataList的问题
- 大数量用户上传文件的服务器性能优化。。。
- Windows Forms应用程序,安装包能不能集成donnet安装包
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="CreateTime" HeaderText="CreateTime" SortExpression="CreateTime" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="CategoryId" HeaderText="CategoryId" SortExpression="CategoryId" />
<asp:CheckBoxField DataField="IsCommended" HeaderText="IsCommended" SortExpression="IsCommended" />
<asp:BoundField DataField="ArticleId" HeaderText="ArticleId" SortExpression="ArticleId" />
<asp:BoundField DataField="ChannelId" HeaderText="ChannelId" SortExpression="ChannelId" />
</Columns>
</asp:GridView>
在页面的Load函数中绑定下面两个函数:
BindDataToDataGrid();//邦定数据到DataGrid中,你也可在此函数中绑定数据到你的GridView中
DataGridStateControl();//此方法主要就是实现你想要的功能(任意单击一行数据的任一地方就可以选中此行)
private void DataGridStateControl()
{
DataGridTableStyle ts = new DataGridTableStyle();
DataGridNoActiveCellColumn aColumnTextColumn;
//DataGridNoActiveCellColumn 是下面另外定义的一个类。
ts.AlternatingBackColor = Color.LightGray;
ts.MappingName = tempTable.TableName;
ts.AllowSorting = true;//允许进行排序
int numCols = tempTable.Columns.Count;
for (int i = 0;i< numCols;i++) //从第二列开始,不显示第一列的“职员编号”
{
aColumnTextColumn = new DataGridNoActiveCellColumn();
aColumnTextColumn.MappingName = tempTable.Columns[i].ColumnName;
aColumnTextColumn.HeaderText = tempTable.Columns[i].ColumnName;
aColumnTextColumn.NullText = "";
aColumnTextColumn.Format = "D";
ts.GridColumnStyles.Add(aColumnTextColumn);
}
this.dataGrid1.TableStyles.Add(ts);
}
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;namespace CustomerInfo
{
internal class DataGridNoActiveCellColumn : System.Windows.Forms.DataGridTextBoxColumn
{
//重载DataGridTextBoxColumn类的Edit方法,以便使点击DataGrid中任一单元格都选中当前行
protected override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
{
int SelectedRow = rowNum;
this.DataGridTableStyle.DataGrid.Select(SelectedRow);
}
}
}