datagridivew单元格内容单击c sharp中的事件代码 [英] datagridivew cell content click event code in c sharp

查看:107
本文介绍了datagridivew单元格内容单击c sharp中的事件代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在datagridview中设计如下;



i有两个复选框如下;

Session1(sess1)session4(sess4)



i有两列我上面提到的session1和session4。



当我选择Sess4(复选框)我想要的sess1(复选框未选中)



我该怎么办?使用csharp。



请帮帮我。



来自下面的代码当我点击时我做的是sess4复选框我显示弹出消息。

但是当我点击sess4复选框时我想要取消选中sess1复选框。



为此我该如何编写代码。



我的代码如下;



Design as follows in datagridview;

i have two checkbox as follows;
Session1 (sess1) session4 (sess4)

i have two columns above i mentioned session1 and session4.

when i select the Sess4(check box) i want sess1 (Check Box to be unchecked)

for that how can i do? using csharp.

Please help me.

from the below code what i done is when i click the sess4 checkbox i show the pop up message.
but when i click the sess4 checkbox i want the sess1 checkbox to be unchecked.

for that how can i write the code.

My Code as follows;

private void DGVCalendar_CellContentClick(object sender, DataGridViewCellEventArgs e)
       {

          if (e.ColumnIndex == DGVCalendar.Columns["Sess4"].Index)
           {MessageBox.Show("Don't Select session if you don't have any session on that day = " + DGVCalendar.Rows[e.RowIndex].Cells[2].Value.ToString());

           }
       }

推荐答案

试试这个,

try this,
private void DGVCalendar_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            try
            {


                DataGridView dgv = (DataGridView)sender;
                DataGridViewCell cell = dgv.CurrentCell;
                if (cell.RowIndex > -1 && (cell.ColumnIndex == 1 || cell.ColumnIndex == 2))
                {
                    if (cell.ColumnIndex == 1)
                    {
                        DGVCalendar.Rows[cell.RowIndex].Cells[1].Value = true;
                        DGVCalendar.Rows[cell.RowIndex].Cells[2].Value = false;
                    }
                    else
                    {
                        DGVCalendar.Rows[cell.RowIndex].Cells[2].Value = true;
                        DGVCalendar.Rows[cell.RowIndex].Cells[1].Value = false;                    
                    }                    
                }
            }
            catch (Exception exc)
            {

                exc.ToString();
            }
        }


这篇关于datagridivew单元格内容单击c sharp中的事件代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆