datagridview列事件处理程序 [英] datagridview column event handlers

查看:59
本文介绍了datagridview列事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用datagridview在Windows应用程序上工作.这是我的第一个使用datagridview的应用程序,并且我对事件处理程序如何与可用于各列的不同类型的对象一起工作遇到问题.例如,第一列是使用复选框的,如果选中此列,则我想禁用另一列.如果未选中该复选框,那么我将启用该列.

谢谢您的任何帮助,谢谢

I''m currently working on a windows application, using a datagridview. This is my first application using a datagridview and I''m having issues with how the event handlers work with the different types of objects available for each column. For example, the first column I''m using a check-box, and if this column is checked I would like to disable the use of another column. If the check-box is not checked, then I would enable the column.

Any assistance would be appreciated, thanks

推荐答案

DataGridView有一个ContentClick事件.处理该事件,并检查是否已选中该复选框.如果是,请冻结该行.看看是否有帮助:

There is a ContentClick event for the DataGridView. Handle that event and check if the checkbox was checked or not. If yes, freeze the row. See if this helps:

void DataGridViewCellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            (sender as DataGridView).Rows[e.RowIndex].Frozen = true;
        }


谢谢d @ nish,我将在表单上尝试此事件处理程序.我开始看到datagridview与标准对象相比到底有多强大,编写了诸如"enabled = true"或"enabled = false"之类的简单代码.一旦该事件对我的checkboxcolumn正常运行,我可以考虑与其他事件一起工作.在我看来,此"CellContentClick"事件将成为datagridview更为常用的事件之一.
Thank you d@nish, I will try this event handler on my form. I''m beginning to see how powerful the datagridview really is compared to your standard objects, writing simple code such as "enabled = true" or "enabled = false". Once I have this event working properly for my checkboxcolumn, I can look into working with my other events. It appears to me, this "CellContentClick" event is going to be one of the more common used events for the datagridview.


这篇关于datagridview列事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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