只能使用datagrid的mousedow事件
如:protected void dataGrid1_MouseDown(object sender, MouseEventArgs e){
// Use the HitTest method to get a HitTestInfo object.
System.Windows.Forms.DataGrid.HitTestInfo hi;
DataGrid grid = (DataGrid) sender;
hi=grid.HitTest(e.X, e.Y);
// Test if the clicked area was a cell.
if(hi.Type==DataGrid.HitTestType.Cell ) {
// If it's a cell, get the GridTable and CurrencyManager of the
// clicked table.
DataGridTableStyle dgt = dataGrid1.TableStyles[0];
CurrencyManager myCurrencyManager =
(CurrencyManager)this.BindingContext
[myDataSet.Tables[dataGrid1.DataMember]];
// Get the Rectangle of the clicked cell.
Rectangle cellRect;
cellRect=grid.GetCellBounds(hi.Row, hi.Column);
// Get the clicked DataGridTextBoxColumn.
DataGridTextBoxColumn gridCol =
(DataGridTextBoxColumn) dgt.GridColumnStyles[hi.Column];
// Insert code to edit the value.
}
如:protected void dataGrid1_MouseDown(object sender, MouseEventArgs e){
// Use the HitTest method to get a HitTestInfo object.
System.Windows.Forms.DataGrid.HitTestInfo hi;
DataGrid grid = (DataGrid) sender;
hi=grid.HitTest(e.X, e.Y);
// Test if the clicked area was a cell.
if(hi.Type==DataGrid.HitTestType.Cell ) {
// If it's a cell, get the GridTable and CurrencyManager of the
// clicked table.
DataGridTableStyle dgt = dataGrid1.TableStyles[0];
CurrencyManager myCurrencyManager =
(CurrencyManager)this.BindingContext
[myDataSet.Tables[dataGrid1.DataMember]];
// Get the Rectangle of the clicked cell.
Rectangle cellRect;
cellRect=grid.GetCellBounds(hi.Row, hi.Column);
// Get the clicked DataGridTextBoxColumn.
DataGridTextBoxColumn gridCol =
(DataGridTextBoxColumn) dgt.GridColumnStyles[hi.Column];
// Insert code to edit the value.
}
{
int columns = DataGrid1.Columns.Count;
if(e.Item.ItemIndex >= 0)
{
for(int i=0;i<DataGrid1.Columns.Count;i++)
{
e.Item.Cells[i].Attributes.Add("onmouserdown","javascript:wondow.close()");
}
}
}
{
{
if (e.Item.ItemIndex >= 0)
{
e.Item.Attributes["onMouseOver"] = "javascript:this.bgColor='#C6D7E7';";
e.Item.Attributes["onMouseOut"] = "javascript:this.bgColor='#ffffff';";
}
}
DataGrid dg;
...
((DataGridTextBoxColumn)dg.TableStyles[0].GridColumnStyles["..."]).TextBox.MouseDown+=new MouseEventHandler(abc);
private void abc(object sender,MouseEventArgs e)
{
...
}
响应键盘一样的道理,请参照:http://www.csdn.net/Develop/read_article.asp?id=15109