在Winform中 Datagrid怎样自动显示行号?
解决方案 »
- c# vs2005 用axWebBrowser控件做一个浏览器,新打开的链接
- C#中如何对datagridview操作
- Sohu OAuth 发帖的问题,一直得到401未授权
- dataGridView(winform)
- WinForm窗体问题
- c#.net,什么是托管资源和非托管资源?怎么分别?
- [求助]关于C#文件上传的简单问题
- 超级经典的题目,学编程的不一定搞的定!
- 请问如何通过Visual C#中用WMI访问远程计算机中的特定文件!谢谢
- 不知[STAThread]、[Category("Appearance")] 等标识的含义
- 在web程序中怎样将当前线程设置为单线程单元(STA)模式,在线等待
- >>>>>>>>>>>>>>>>>>datatable的select方法的问题<<<<<<<<<<<<<<<<<<<<<<<
datagrid有这个属性的,自己找下吧
--------------------------------------------------- M$ 标准的datagrid 没有这个属性吧一些第3方的控件就有
private void dataGrid1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
int intRow =0;
int intCellHehight = dataGrid1.GetCellBounds(intRow, 0).Height + 1;
int intY = dataGrid1.GetCellBounds(intRow, 0).Top + 2;
int intY0=intY-intCellHehight-1;//**********加新语句
//e.Graphics.DrawString("行号", dataGrid1.Font, new SolidBrush(Color.Black), 5, intY-intCellHehight-1); //把"行号" 换成你的内容*********移到下面的环后面
CurrencyManager cm = (CurrencyManager) this.BindingContext[dataGrid1.DataSource, dataGrid1.DataMember];
while(intY < dataGrid1.Height - intCellHehight && intRow < cm.Count)
{
//get & draw the header text...
string text = string.Format("{0}", (intRow+1)); //把(intRow+1)换成你的内容
e.Graphics.DrawString(text, dataGrid1.Font, new SolidBrush(Color.Black), 12, intY);
intY += intCellHehight;
intRow++;
}
e.Graphics.DrawString("序号", dg.Font, new SolidBrush(Color.Black), 5, intY0);
}
dt.Columns["INDEX"].AutoIncrement = true; DataGrid1.DataSource = dt;
DataGrid1.DataBind();
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.SelectedItem || e.Item.ItemType == ListItemType.EditItem)
{
e.Item.Cells[1].Text = Convert.ToString(MyDataGrid.CurrentPageIndex*15+e.Item.ItemIndex+1);
}
}