C#中,模拟DataGridView的CellClick事件
来源:互联网 发布:linux 关闭tomcat 编辑:程序博客网 时间:2024/04/28 02:46
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("Age");
for (int i = 0; i < 5; i++)
{
dt.Rows.Add();
dt.Rows[i][0] = i;
dt.Rows[i][1] = i.ToString() + "Name";
dt.Rows[i][2] = (i + 1) * 5;
}
dataGridView1.DataSource = dt;
}
//第一个参数是第几列的意思,第二个参数是第几行的意思。
//所有的参数是以0开始的。
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show(e.RowIndex.ToString() + ":" + e.ColumnIndex.ToString());
}
private void button1_Click(object sender, EventArgs e)
{
//dataGridView1_CellClick(dataGridView1, new DataGridViewCellEventArgs(1, 2));
dataGridView1_CellClick(dataGridView1, new DataGridViewCellEventArgs(dataGridView1.SelectedCells[0].ColumnIndex, dataGridView1.SelectedCells[0].RowIndex));
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("Age");
for (int i = 0; i < 5; i++)
{
dt.Rows.Add();
dt.Rows[i][0] = i;
dt.Rows[i][1] = i.ToString() + "Name";
dt.Rows[i][2] = (i + 1) * 5;
}
dataGridView1.DataSource = dt;
}
//第一个参数是第几列的意思,第二个参数是第几行的意思。
//所有的参数是以0开始的。
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show(e.RowIndex.ToString() + ":" + e.ColumnIndex.ToString());
}
private void button1_Click(object sender, EventArgs e)
{
//dataGridView1_CellClick(dataGridView1, new DataGridViewCellEventArgs(1, 2));
dataGridView1_CellClick(dataGridView1, new DataGridViewCellEventArgs(dataGridView1.SelectedCells[0].ColumnIndex, dataGridView1.SelectedCells[0].RowIndex));
}
}
}
参考:http://blog.csdn.net/dogfish/article/details/7002712
- C#中,模拟DataGridView的CellClick事件
- C#中,模拟DataGridView的CellClick事件
- WinForm中DataGridView的 CellClick 事件的代码
- DataGridView中 事件CellClick,CellMouseClick,CellContentClick的区别(亲自实践)
- DataGridView中CellClick,CellMouseClick,CellContentClick的区别
- DataGridView中CellContentClick和CellClick区别
- c#中datagridview的EditingControlShowing事件
- C#中DataGridView鼠标左键双击事件的添加
- c#中事件模型的模拟
- C#里,如何模拟DataGridView里的一个Cell的Click事件。
- C# DataGridView中ComboBox下拉更改事件
- DataGridView.CellContentClick 事件的C#例子
- C#中DataGridView的使用
- 结合grid的cellclick事件来讲解api的事件理解
- DataGridView中ComboBox列的触发事件
- DataGridView中comboBox(DataGridViewComboBoxColumn)的事件编写
- Winform中DataGridView的复选框事件
- DataGridView中comboBox(DataGridViewComboBoxColumn)的事件编写
- delphi 6 中cobra 找不到orapas60.dll的解决方法
- 移动GPU:高通Adreno图形处理器全解析
- MFC wINMain的封装
- #Pragma Pack(n)与内存分配
- nodeJS入门例子一—全局对象之控制台(console)
- C#中,模拟DataGridView的CellClick事件
- Sed简介 如何做替换
- 使用cscope
- C++ Primer:Exercises Section 1.1.1
- case语句按条件更新数据列
- 一站式WPF--依赖属性(DependencyProperty)二
- 第四部分 为Cassandra1.0.x准备java运行环境
- <转> Android开发者应该深入学习的10个开源应用项目
- Windows环境下Unicode编程总结