列有名字的属性么?应该只有HEADER的属性吧,那好象是e.Item.Cells[i].HeaderText
解决方案 »
- ToolStrip工具栏合并后子窗体更改ToolStrip Button状态
- 向大家求教一个问题:怎样改变TextBox或Label的字号
- dll动态库的有效期是怎么控制的?》
- 如何精通C# 初学者
- c# 关于网络编程的疑问
- C#与C++.net有什么不同啊?
- 改变字体问题。C#入门经典书中一例子
- 用TC做一个类似WINDOWS那样的画板谁能帮帮说下?
- 将datatable中的数据写成txt文件的速度问题?? 50分 在线等!!
- 在window98中如何正确的安装.net(安装后的.net要正确无误的)?
- 求助:C#.net如何制作安装程序,安装程序能够自动创建oracle表空间、用户,并创建数据表?
- 锁定对象内存地址的问题
不如说:
void Page_Load(Object o,EventArgs E)这里的e就是事件参数。
我是在CurrentCellChanged事件里面试的这个e参数.
((DataGrid)sender).Item.Cells[i].HeaderText;
DataGrid1是你的DataGrid的name
DataGrid 类 | DataGrid 成员 | System.Windows.Forms 命名空间
语言
C#C++JScriptVisual Basic全部显示
获取或设置指定单元格的值。[C#] 在 C# 中,该属性为 DataGrid 类的索引器。重载列表
获取或设置指定的 DataGridCell 的值。[Visual Basic] Overloads Public Default Property Item(DataGridCell) As Object
[C#] public object this[DataGridCell] {get; set;}
[C++] public: __property Object* get_Item(DataGridCell);
public: __property void set_Item(DataGridCell, Object*);
[JScript] DataGrid.Item (DataGridCell)
获取或设置位于指定行和列的单元格的值。[Visual Basic] Overloads Public Default Property Item(Integer, Integer) As Object
[C#] public object this[int, int] {get; set;}
[C++] public: __property Object* get_Item(int, int);
public: __property void set_Item(int, int, Object*);
[JScript] DataGrid.Item (int, int)
示例
[Visual Basic, C#] 下面的示例输出位于指定行和索引处的单元格所包含的值。[Visual Basic, C#] 注意 此示例显示如何使用 Item 属性(DataGrid 索引器)的一个重载版本。有关其他可用示例,请参阅单独的重载主题。
[Visual Basic]
Private Sub PrintCells(ByVal myGrid As DataGrid)
Dim iRow As Integer
Dim iCol As Integer
Dim myTable As DataTable
' Assumes the DataGrid is bound to a DataTable.
myTable = CType(DataGrid1.DataSource, DataTable)
For iRow = 0 To myTable.Rows.Count - 1
For iCol = 0 To myTable.Columns.Count - 1
Console.WriteLine(myGrid(iRow, iCol))
Next iCol
Next iRow
End Sub[C#]
private void PrintCellValues(DataGrid myGrid){
int iRow;
int iCol;
DataTable myTable;
// Assumes the DataGrid is bound to a DataTable.
myTable = (DataTable) dataGrid1.DataSource;
for(iRow = 0;iRow < myTable.Rows.Count ;iRow++) {
for(iCol = 0;iCol < myTable.Columns.Count ;iCol++) {
Console.WriteLine(myGrid[iRow, iCol]);
}
}
}
---------------------------------------------------------------------
MSDN上复制过来的
{
int i = dataGrid1.CurrentCell.ColumnNumber;
string str = AuthorData.Tables[0].Columns[i].ColumnName;
textBox1.Text = str;
}
{
//当前选中的行号
int iRow = this.dataGrid1.CurrentCell.RowNumber;
//当前选中的列号
int iCol = this.dataGrid1.CurrentCell.ColumnNumber;
DataGridTableStyle ts = new DataGridTableStyle(true);
ts.MappingName = this.dataGrid1.DataMember;
this.dataGrid1.TableStyles.Clear();
this.dataGrid1.TableStyles.Add(ts);
MessageBox.Show(ts.GridColumnStyles[iCol].HeaderText);
}