登录
首页 » C#源码 » C# 显示DataGridView控件中选定的单元格、行和列

C# 显示DataGridView控件中选定的单元格、行和列

于 2022-03-18 发布 文件大小:142.92 kB
0 235
下载积分: 2 下载次数: 1

代码说明:

Visual C#显示选择的DataGridView单元格,获取DataGridView控件中选定的单元格、行和列,测试前请连接好数据库,实现此功能核心代码如下:   if (customersDataGridView.AreAllCellsSelected(true))   {    MessageBox.Show("所有单元格已经被选择!", "信息提示",MessageBoxButtons.OK);   }   else   {    System.Text.StringBuilder MyInfo =new System.Text.StringBuilder();    for (int i = 0;    i < MyCount; i++)    {    MyInfo.Append("行号: ");    MyInfo.Append(customersDataGridView.SelectedCells[i].RowIndex.ToString());    MyInfo.Append(", 列号: ");    MyInfo.Append(customersDataGridView.SelectedCells[i].ColumnIndex.ToString());    MyInfo.Append(", 单元格值: ");    MyInfo.Append(customersDataGridView.SelectedCells[i].Value.ToString());    MyInfo.Append(Environment.NewLine);    }    MyInfo.Append("一共选择了: " + MyCount.ToString()+"个单元格");    MessageBox.Show(MyInfo.ToString(), "信息提示", MessageBoxButtons.OK);   }

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

发表评论

0 个回复

  • C# 实现窗体控件值与数据库字段绑定
    C# 实现窗体控件值与数据库字段绑定,DataBinding的用法例子,基本的数据库操作示例,学习MyAdapter、SqlDataAdapter、DataBindings、BindingContext等的用法,测试例子如上图所示。
    2022-03-18 00:24:48下载
    积分:1
  • C# 查询订购产品ID为51的客户信息
    C# 查询订购产品ID为51的客户信息,需要连接数据库来测试,相关代码分享如下:   //查询订购产品ID为51的客户信息   SqlConnection MyConnection = new SqlConnection(@"Data Source =luobin-PCSQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True");   MyConnection.Open();   DataSet MyDataSet = new DataSet("CustomerOrdersDetails");   SqlDataAdapter MyCustomerAdapter = new SqlDataAdapter("SELECT * FROM Customers", MyConnection);   MyCustomerAdapter.Fill(MyDataSet, "Customers");   DataTable MyTable = new DataTable();   MyCustomerAdapter.Fill(MyTable);   SqlDataAdapter MyOrderAdapter = new SqlDataAdapter("SELECT * FROM Orders", MyConnection);   MyOrderAdapter.Fill(MyDataSet, "Orders");   SqlDataAdapter MyDetailAdapter = new SqlDataAdapter("SELECT * FROM [Order Details]", MyConnection);   MyDetailAdapter.Fill(MyDataSet, "OrderDetails");   MyConnection.Close();   MyDataSet.Relations.Add("CustOrders",MyDataSet.Tables["Customers"].Columns["CustomerID"],MyDataSet.Tables["Orders"].Columns["CustomerID"]).Nested = true;   MyDataSet.Relations.Add(
    2023-04-28 12:35:03下载
    积分:1
  • MFC股票软件源码
    MFC股票软件源码,用来分析股票数据。
    2022-07-06 19:06:18下载
    积分:1
  • C# WPF实现图片浮雕、凹凸的图像效果
    Visual C# WPF实现图片浮雕、凹凸的图像效果,看上去很有雕刻的效果,这个功能对于熟悉PS的朋友,可能不陌生,用C#的WPF技术,可以轻松实现类似效果,只是说法不一样,在本例中,叫做“凹凸位图特效”,本代码在功能实现上,分为全部实现和局部实现,代码参考如下:   private void button1_Click(object sender, RoutedEventArgs e)   {//凹凸位图特效全部作用于图像    this.image1.BitmapEffectInput = null;    var MyEffect = new System.Windows.Media.Effects.EmbossBitmapEffect();    MyEffect.Relief = 0.8;    MyEffect.LightAngle =320;    this.image1.BitmapEffect = MyEffect;   }   private void button2_Click(object sender, RoutedEventArgs e)   {//凹凸位图特效部分作用于图像    var MyEffect = new System.Windows.Media.Effects.EmbossBitmapEffect();    MyEffect.Relief = 0.8;    MyEffect.LightAngle = 320;    this.image1.BitmapEffect = MyEffect;    var MyInput = new System.Windows.Media.Effects.BitmapEffectInput();    MyInput.AreaToApplyEffect = new Rect(.25, .25, .50, .50);    MyInput.AreaToApplyEffectUnits = System.Windows.Media.BrushMappingMode.RelativeToBoundingBox;    this.image1.BitmapEffectInput= MyInput;   }   完整
    2022-02-20 09:13:59下载
    积分:1
  • C# 通过存储过程实现员工ID自动编号
    C# 实现自动ID,通过存储过程实现员工自动编号,这个在平时的编程中很实用,自动编号使用存储过程来实现,比较高级一些,且数据库需要支持存储过程。   con.Open();   SqlCommand cmd = new SqlCommand();   string strSql = "insert into 员工个人信息 values ( + label6.Text + , + this.textBox2.Text + , + this.textBox3.Text + , + this.textBox5.Text + , + this.textBox4.Text + )";   cmd.CommandText = strSql;   cmd.Connection = con;   cmd.ExecuteNonQuery();   con.Close();   MessageBox.Show("成功添加信息");   this.groupBox1.Enabled = false;
    2022-05-31 12:11:24下载
    积分:1
  • C# 键盘Ctrl+g控制蜂鸣器播放声音
    Visual C#播放声音,运行程序后,操作键盘上的Ctrl+g组合键发出蜂鸣声...这里的拖放声音是蜂鸣声,从音箱里发出,并不是从机箱的蜂鸣器发声。实现的过程和细节代码如下:   //导入 Windows Beep() API 函数   [DllImport("kernel32.dll")]   private static extern bool Beep(int freq, int dur);   // 定义PlaySound()要使用的常数   public const int SND_FILENAME = 0x00020000;   public const int SND_ASYNC = 0x0001;   // 导入 Windows PlaySound() 函数   [DllImport("winmm.dll")]   public static extern bool PlaySound(string pszSound,    int hmod,    int fdwSound);   [STAThread]   static void Main(string[] args)   {    // 使用Ctrl+g发出蜂鸣声    Console.Write("a");    Console.WriteLine("使用Ctrl+g发出蜂鸣声...");    Console.ReadLine();    // 使用 Windows API 发出蜂鸣声    Beep(800, 200);    Console.WriteLine("使用 Windows API 发出蜂鸣声...");    Console.ReadLine();    // 播放bells.wav文件    PlaySound("bells.wav",    0,    SND_FILENAME | SND_ASYNC);    Console.WriteLine("播放bells.wav文件...");    Console.ReadLine();   }
    2022-05-23 17:14:52下载
    积分:1
  • C# 编写多种窗口排列方式的MDIForm窗体
    C# 实现MDIForm窗体功能,代码中实现了3个MDI子窗口,并以水平平铺、垂直平铺、层叠排列的方式实现多种子窗口的排列布局,其主要代码在form1.cs中,其它文件为生成子窗口的文件,关键代码如下:   private void toolStripMenuItem1_Click(object sender, EventArgs e)   {    Form2 frm2 = new Form2();//实例化Form2    frm2.MdiParent = this;//设置MdiParent属性,将当前窗体作为父窗体    frm2.Show();//使用Show方法打开窗体    Form3 frm3 = new Form3();//实例化Form3    frm3.MdiParent = this;//设置MdiParent属性,将当前窗体作为父窗体    frm3.Show();//使用Show方法打开窗体    Form4 frm4 = new Form4();//实例化Form4    frm4.MdiParent = this;//设置MdiParent属性,将当前窗体作为父窗体    frm4.Show();//使用Show方法打开窗体   }   private void 水平平铺ToolStripMenuItem_Click(object sender, EventArgs e)   {    LayoutMdi(MdiLayout.TileHorizontal);//使用MdiLayout枚举实现水平平铺   }   private void 垂直平铺ToolStripMenuItem_Click(object sender, EventArgs e)   {    LayoutMdi(MdiLayout.TileVertical);//使用MdiLayout枚举实现垂直平铺   }   private void 层叠排列ToolStripMenuItem_Click(object sender, EventArgs e)   {    LayoutMdi(MdiLayout.Cascade);//使用MdiLayout枚举实现层叠排列   }
    2022-03-07 15:00:14下载
    积分:1
  • C#结合数据库使用二进制存取用户头像图片
    C#结合数据库使用二进制存取用户头像图片,这个例子的功能主是把图片数据以二进制格式存储在数据库中,这样可方便数据的移植,不过图像比较占空间,会导致数据库文件会大不少。这个例子以存储用户的头像图片为例,演示如何将图片转换为二进制数据并存储在数据库中。本实例还演示了从数据库中读取数据,然后在DataGridView中显示用户名称,使用数据库中存储的二进制头像实例化内存数据流。
    2022-03-21 01:19:34下载
    积分:1
  • Visual C# 查询指定时间间隔的数据
    Visual C# 查询指定时间间隔的数据,根据学生出生年月查询学生年龄,代码如下:   private DataTable GetMessage()   {    string P_Str_ConnectionStr = string.Format(//创建数据库连接字符串    @"server=WIN-GI7E47AND9RLS;database=db_TomeTwo;uid=sa;pwd=");    string P_Str_SqlStr = string.Format(//创建SQL查询字符串    "select 学生姓名,出生年月 from tb_Student");    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-03-02 08:45:17下载
    积分:1
  • C# 强制断开SQLServer服务
    C# 强制断开SQLServer服务,在C#的程序中断开SQL服务器,其实实现起来挺简单,虽然不常用,就当做是一个简单的SQL技巧吧,了解一下总是没错的,代码如下:   string strShutdown = "SHUTDOWN WITH NOWAIT";//创建SQL字符串   SqlCommand cmd = new SqlCommand();//创建命令对象   cmd.Connection = con;//设置连接属性   cmd.Connection.Open();//打开数据库连接   cmd.CommandText = strShutdown;//设置将要执行的SQL语句   cmd.ExecuteNonQuery();//执行SQL语句   MessageBox.Show("已成功断开服务");//弹出消息对话框
    2022-08-25 01:38:36下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载