Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 17-Apr-12 1:07am
v2

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[^]
 
Share this answer
 
Comments
veenavipeesh 17-Apr-12 2:56am    
i need multiselection of rows.but multiple rows can be selected only by checking the columncheckbox on the grid.user must not select by dragging.
VJ Reddy 17-Apr-12 3:18am    
I don't think there is a built in option in DataGridView to enable multi select and disable selection by dragging on rows. One option can be to disable selection by user and to handle selection programmatically. i.e. in the CellValue changed event, if the required cell is checked or unchecked then to change the back ground color of the row accordingly.
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.
C#
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.
 
Share this answer
 
v2
Hi,

Set AllowDrop property if DataGridView to false
 
Share this answer
 
Not clear, drag columns?
If u don't want to do anything on DataGridView, u can set property ReadOnly=True on Properties toolbox

Regards
 
Share this answer
 
Comments
veenavipeesh 17-Apr-12 2:39am    
i mean, can i restrict selecting rows of datagridview by dragging on them?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900