=0){this.dataGridView1.Select();varMyInfo=this.dataGridView1.Rows[MyHit.RowIndex].Cells[MyHit.ColumnIndex].Value.ToString();MessageBox.Show("刚才的选择是:"+MyInfo,"信息提示",MessageBoxButtons.OK);}}-IMDN开发者社群-imdn.cn"> =0){this.dataGridView1.Select();varMyInfo=this.dataGridView1.Rows[MyHit.RowIndex].Cells[MyHit.ColumnIndex].Value.ToString();MessageBox.Show("刚才的选择是:"+MyInfo,"信息提示",MessageBoxButtons.OK);}} - IMDN开发者社群-imdn.cn">
登录
首页 » C#源码 » C# 获取DataGridView鼠标单击单元格值

C# 获取DataGridView鼠标单击单元格值

于 2022-07-18 发布 文件大小:12.54 kB
0 128
下载积分: 2 下载次数: 1

代码说明:

C# 单击 鼠标获取DataGridView单元格的值,这个例子需要连接SQL数据库,测试时候没连接成功,截图也不准确,请大家下载源码,自己配置环境调试吧,这是核心代码部分:   private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)   {//获取DataGridView鼠标单击单元格值    var MyInfo = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();    MessageBox.Show("刚才的选择是:" + MyInfo, "信息提示", MessageBoxButtons.OK);   }   private void dataGridView1_MouseUp(object sender, MouseEventArgs e)   {//单击鼠标获取DataGridView单元格值    var MyHit = this.dataGridView1.HitTest(e.X, e.Y);    if (MyHit.RowIndex >= 0)    {    this.dataGridView1.Select();    var MyInfo = this.dataGridView1.Rows[MyHit.RowIndex].Cells[MyHit.ColumnIndex].Value.ToString();    MessageBox.Show("刚才的选择是:" + MyInfo, "信息提示", MessageBoxButtons.OK);    }   }

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • 验证识别c#
    验证码识别c# 源码. 可以识别多重验证码。可以稍作修改识别更多的类型。已经使用过。可执行。 可以识别多重验证码。可以稍作修改识别更多的类型。已经使用过。可执行。
    2022-03-25 12:44:31下载
    积分:1
  • C# 简单嵌套查询的例子
    分享一个C# 简单嵌套查询的例子,查询总分在580分以上的学生信息。具体代码如下:   /// 查询数据库信息   /// 方法返回DataTable对象   private DataTable GetGrade()   {    string P_Str_ConnectionStr = string.Format(//创建数据库连接字符串    @"server=WIN-GI7E47AND9RLS;database=db_TomeTwo;uid=sa;pwd=");    string P_Str_SqlStr = string.Format(//创建SQL查询字符串    @"SELECT 学生姓名,学生编号, 性别,出生年月,年龄,所在学院,所学专业 FROMtb_Student WHERE 学生编号 IN (SELECT 学生编号 FROM tb_Grade WHERE 总分>=580)");    SqlDataAdapter P_SqlDataAdapter = new SqlDataAdapter(//创建数据适配器    P_Str_SqlStr, P_Str_ConnectionStr);    DataTable P_dt = new DataTable();//创建数据表    P_SqlDataAdapter.Fill(P_dt);//填充数据表    return P_dt;//返回数据表   }
    2022-12-23 02:20:03下载
    积分:1
  • vb串口调试助手,可用于自己做调试测试工具
    1.用易懂的VB语言编程   2.可设置串口号波特率   3.支持十六进或字符形式发送或接收,可定时发送。3,可自己换程序的图片
    2022-07-13 02:02:52下载
    积分:1
  • 《Visual.C#.编程精彩百例》配套随书光盘
    《Visual.C#.编程精彩百例》配套随书光盘源码,涉及到书中方方面面的实例,包括界面设计、数据库、系统控制、基础知识、算法、多媒体播放等众多类型的源代码,是学习C#基础编程很好的实例集。
    2023-09-09 21:35:05下载
    积分:1
  • C# 从RichTextBox 控件中提取文本内容
    C# 从RichTextBox 控件中提取文本内容,并设置RichTextBox 控件中的字体大小-附完整源代码,   private void button1_Click(object sender, RoutedEventArgs e)   {//从RichTextBox 控件中提取文本内容    TextRange MyText = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd);    MessageBox.Show(MyText.Text, "RichTextBox控件中的文本内容",MessageBoxButton.OK);   }   private void button2_Click(object sender, RoutedEventArgs e)   {//设置RichTextBox 控件中的字体大小    TextRange MyText = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd);    MyText.ApplyPropertyValue(TextElement.FontSizeProperty, 36.00);    MyText.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);   
    2022-09-21 17:55:02下载
    积分:1
  • C#在图片格式转换时设置JPEG压缩级别的实现
    C#在转换图像格式时设置JPEG压缩级别,运行程序在窗口上单击按钮后,会生成多个版本不同压缩级别的图片,图片大小字节都不一样,如下代码是实现本功能的核心代码:   Bitmap MyBitmap = new Bitmap(@"J001.jpg");   ImageCodecInfo MyDecoder = null;   ImageCodecInfo[] MyDecoders = ImageCodecInfo.GetImageDecoders();   foreach (ImageCodecInfo MyFormat in MyDecoders)   {    if (MyFormat.FormatID == ImageFormat.Jpeg.Guid)    {    MyDecoder = MyFormat;    }   }   System.Drawing.Imaging.Encoder MyEncoder =    System.Drawing.Imaging.Encoder.Quality;   EncoderParameters MyEncoderParameters = new EncoderParameters(1);   //以50中级压缩图像   EncoderParameter MyEncoderParameter = new EncoderParameter(MyEncoder, 50L);   MyEncoderParameters.Param[0] = MyEncoderParameter;   MyBitmap.Save("J50L.jpg", MyDecoder, MyEncoderParameters);   //以100高级压缩图像   MyEncoderParameter = new EncoderParameter(MyEncoder, 100L);   MyEncoderParameters.Param[0] = MyEncoderParameter;   MyBitmap.Save("J99L.jpg", MyDecoder, MyEncoderParameters);   //以0低级压缩图像   MyEncoderParameter = new Enc
    2022-05-18 00:19:47下载
    积分:1
  • C#多个读写文本文件的方法含示例
    C#多个读写文本文件的方法含示例,比如"以文本行为单位写文本文件、以文本行为单位读文本文件、一次性向文本文件写入数据、一次性从文本文件读取数据、一次性向文本文件追加数据。
    2022-05-12 17:08:46下载
    积分:1
  • C# 获取本地打印服务器后台文件的路径
    Visual C# MyWinWPF.rar,核心代码分享如下:   private void button1_Click(object sender, RoutedEventArgs e)   {//获取本地打印服务器后台文件的路径    var MyPrintServer = new System.Printing.LocalPrintServer();    string MyInfo = "本地打印服务器后台文件的路径是:" + MyPrintServer.DefaultSpoolDirectory;    MessageBox.Show(MyInfo, "信息提示", MessageBoxButton.OK);   }
    2022-01-23 11:13:33下载
    积分:1
  • C# 字符串综合处理程序
    C# 字符串综合处理程序,功能主要有:   获取含有中文的字符串实际长度、在字符串指定位置插入子字符串、   从分隔符字符串中析取子字符串、合并字符串数组中的字符串元素、在字符串中删除指定的子字符串、在字符串中替换指定的子字符串、在字符串中附加格式化的字符串、将字符串转换为标准的日期格式、获取指定字符在字符串中的位置、不区分字母大小写比较字符串、转换字符串中的大小写字母、去除字符串中的空白字符、将指定值转换为字符串表示形式、将带分节号的字符串转换成数字等。。。
    2022-01-22 08:06:13下载
    积分:1
  • C# 获取Access数据库的数据表名称
    C# 获取Access数据库的数据表名称,private void button1_Click(object sender, EventArgs e)   {//获取Access数据库的数据表名称    string MyAccessDBFile = @"F:Northwind.mdb";    string MyConnectString ="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +MyAccessDBFile;    var MyConnection = new System.Data.OleDb.OleDbConnection(MyConnectString);    MyConnection.Open();    var MyTables = MyConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });    string MyInfo = MyAccessDBFile + "数据库的数据表包括:";    foreach (DataRow MyRow in MyTables.Rows)    {    string MyTable = MyRow["TABLE_NAME"].ToString();    MyInfo += MyTable + "、";    }    MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK);   }
    2023-01-05 19:40:03下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载