Click here to Skip to main content
15,894,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have written below code to select single check box if i need to select all the checkboxes how i need to do it,please suggest

What I have tried:

private void FillGridView()
		{
			try {
				if (System.IO.Directory.Exists(SelectedPath)) {
					String[] files = System.IO.Directory.GetFiles(SelectedPath);
					DataGridViewCheckBoxColumn CheckBoxColumn = new DataGridViewCheckBoxColumn();
					DataGridViewTextBoxColumn FileNameColumn = new DataGridViewTextBoxColumn();                
					CheckBoxColumn.HeaderText = "Select";
					FileNameColumn.HeaderText = "File Name";                
					dataGridView1.Columns.Clear();
					dataGridView1.Rows.Clear();               
					dataGridView1.Columns.Add(CheckBoxColumn);
					CheckBoxColumn.Selected=true;
					dataGridView1.Columns.Add(FileNameColumn);   
					dataGridView1.Columns[1].ReadOnly = true;				  				            
					for (int i = 0; i < files.Length; i++) {
						dataGridView1.Rows.Add(false, files[i]); 									
					}     									
				}				
			} catch (Exception e) {
				MessageBox.Show(e.Message);
			}
		}
Posted
Updated 24-May-18 23:16pm

1 solution

See example here: c# - Check/Uncheck a checkbox on datagridview - Stack Overflow[^]

As you can see in the example, you can do it like this in your for loop:
DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)row.Cells[0];
chk.Value = chk.TrueValue;
 
Share this answer
 
v2
Comments
Member 13818142 25-May-18 5:26am    
i hve done with checking the single checkbox but i need to select all files at a time..

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