日期:2014-05-18 浏览次数:20732 次
//单元格点击事件 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { //获取某个单元格的值的数据类型名称 MessageBox.Show(dataGridView1[e.ColumnIndex, e.RowIndex].Value.GetType().Name); }
------解决方案--------------------
for循环选中列
------解决方案--------------------
foreach (DataGridViewTextBoxCell cell in dataGridView1.SelectedCells) { string typename = cell.Value.GetType().Name; }
------解决方案--------------------
楼上是对的,稍微修改一下
private void button1_Click(object sender, EventArgs e) { List<string> list = new List<string>(); foreach (DataGridViewCell cell in dataGridView1.SelectedCells) { list.Add("[" + cell.OwningColumn.Name + "]" + "的数据类型为:" + cell.Value.GetType().Name); } foreach (string s in list.Distinct<string>()) MessageBox.Show(s); }
------解决方案--------------------
using System.Linq;