在DatagridView上拖动 [英] Dragging on DatagridView

查看:105
本文介绍了在DatagridView上拖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datagridview,其中有一些文本框列和一个复选框列.我只想在单击复选框列时才选择一行.可以选择多个行.但是不允许通过拖动来选择行.我该怎么办

i have a datagridview with some textbox columns and one checkbox column.i want to make a row selected only when clicking on the checkbox column.multiple rows can be selected.but selection of rows by dragging is not allowed.what can i do?

推荐答案

我认为,通过在行上拖动来禁用行选择意味着禁用行的多个选择,这可以通过将MultiSelect 属性设置为DataGridView False ,如此处所述.
DataGridView.MultiSelect属性 [
I think, disabling selection of rows by dragging on them means disabling multiple selection of rows, which can be achieved by setting the MultiSelect property of DataGridView to False as explained here.
DataGridView.MultiSelect Property[^]


我已经检查了是否选中了该复选框,以及是否选中了该复选框,然后设置了相应的行.我将此代码写在dataGridView的CurrentCellDirtyStateChanged,CellClick和RowLeave事件中.
i have checked whether the checkbox is checked or not and if the checkbox is checked, then set the corresponding row selected.I wrote this code in the CurrentCellDirtyStateChanged,CellClick and RowLeave events of the dataGridView.
for (int i = 0; i< dataGridView1.RowCount; i++)
 {
   if(Convert.ToBoolean(dataGridView1.Rows[i].Cells["checkboxname"].Value)== true)
       {
         dataGridView1.Rows[i].Selected = true;
       }
     else
      {
        dataGridView1.Rows[i].Selected = false;
       }
 }


然后拖动无法使行处于选中状态.


Then dragging could not make the rows selected.




如果DataGridView 设置为AllowDrop 属性,则为false
Hi,

Set AllowDrop property if DataGridView to false


这篇关于在DatagridView上拖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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