DataGridView 只读单元格 [英] DataGridView read only cells

查看:40
本文介绍了DataGridView 只读单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含大量数据的绑定 DataGridView.问题是某些单元格必须是只读的,而且当用户在单元格之间使用 TAB 或 ENTER 导航时,应该绕过只读单元格.加载后立即使某些特定单元格只读的最佳方法是什么?

I have a binded DataGridView that contains a large amount of data. The problem is that some cells has to be ReadOnly and also when the user navigates with TAB or ENTER between cells, the ReadOnly cells should be bypassed. What's the best way of making some specific cells ReadOnly imediatly after loadging?

考虑到网格有大量数据,在设置 DataSource 后循环遍历单元格不是一个好主意.此外,在 CellEnter 上使单元格只读不起作用,因为在使用 TAB 键导航时,我必须已经知道下一个单元格是否为只读.

Looping through cells after I set DataSource is not a good idea taking in consideration that the grid has a large amount of data. Also, making the cell ReadOnly on CellEnter does not work because when navigating with TAB key I have to already know if the next cell is ReadOnly or not.

推荐答案

在绑定数据之前尝试使列而不是单个单元格只读:

Try to make the column rather than individual cells readonly before binding the data:

this.dgrid.Columns["colName"].ReadOnly = true;

如果您需要对列中的单个单元格进行处理,那么您将不得不循环并像这样设置它们:

If you need to do for individual cells within the column, then you will have to loop and set them like this:

this.dgridvwMain.Rows[index].Cells["colName"].ReadOnly = true;

这篇关于DataGridView 只读单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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