C# DataGridView操作小结(3.DataGridView点击事件dataGridView1_CellContentClick的操作)

这个直接上代码,操作dataGridView1_CellContentClick的单元格,这里有一点需要注意的是,个人推测可能是由于单元的事件过多,所以在设置操作单元格时只能去点击单元格中的字,否则就不会有响应事件

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //判断选中的有多少
            if (dataGridView1.Rows.Count > 0) {
                int j =0;
                for (int i = 0; i < dataGridView1.Rows.Count; i++) 
                {
                   string _selectValue = dataGridView1.Rows[i].Cells["Column1"].EditedFormattedValue.ToString();
                    if (_selectValue == "True") 
                    {
                        j++;

                    }  
                }
                label5.Text = j.ToString();
            }
            //当点击词频时排序
            if (e.ColumnIndex == 5 && e.RowIndex == -1)
            {
                if (flag == -1)
                {
                    flag = 1;
                }
                else
                {
                    flag = -1;
                }
                if (!string.IsNullOrEmpty(comboBox1.Text))
                {
                    if (comboBox1.Text == "动词")
                    {
                        SearchGroup(flag, "v", 1);
                        label10.Text = 1.ToString();
                    }
                    else if (comboBox1.Text == "名词")
                    {
                        SearchGroup(flag, "n", 1);
                        label10.Text = 1.ToString();
                    }
                }
                else
                {
                    SearchGroup(flag, "", 1);
                    label10.Text = 1.ToString();
                }
            }
            else
            if (e.ColumnIndex == 6 && e.RowIndex == -1)
            {
                //词性的下拉框

            }
            else
            if (e.ColumnIndex == 4 && e.RowIndex != -1)
            {
                words = dataGridView1.Rows[e.RowIndex].Cells["词语"].EditedFormattedValue.ToString();
                CompanyGroup(words, 1);
                label15.Text = 1.ToString();
            }
            else if (e.ColumnIndex == 1 && e.RowIndex != -1)
            {
                string words = dataGridView1.Rows[e.RowIndex].Cells["词语"].EditedFormattedValue.ToString();
                Form2 Form2 = new Form2(words, "整体", 20, 1);
                Form2.ShowDialog();
            } 
            else if (e.ColumnIndex == 2 && e.RowIndex != -1)
            {
                //操作
                //查询该分组
                StringBuilder sql = new StringBuilder();
                sql.AppendFormat("select {0} from {1} ", "*", "[dbo].[分词分组表]");
                SqlDataAdapter sda = new SqlDataAdapter(sql.ToString(), myConnection);
                if (myConnection.State != ConnectionState.Open)
                    myConnection.Open();
                DataTable dt = new DataTable();
                sda.Fill(dt);
                myConnection.Close();
                Fenzu Fenzu = new Fenzu(dt, dataGridView1.Rows[e.RowIndex].Cells["词语"].EditedFormattedValue.ToString());
                Fenzu.Show();
            }
        }

界面如下

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值