[RESOLVED] [2005] Only enable 1 column in dataGridview?
Is there a simple way to only enable the 1st column in a datagrid. I want the user to simply select a range or single items from column 1 which are then added to a listbox.
The problem is if they start selecting from the other columns. I put different events in like on Cell Click etc... to jump to the 1st column but there's too much that can go wrong. Would be simpler to just only enable 1 column.
Re: [2005] Only enable 1 column in dataGridview?
Code:
For i As Int32 = 1 To grid.Columns.Count - 1
grid.Columns(i).ReadOnly = True
Next
or
Code:
For i As Int32 = 1 To grid.Columns.Count - 1
grid.Columns(i).Visible= True
Next
Re: [2005] Only enable 1 column in dataGridview?
I need all columns to be displayed, but only the cells in column 1 to actually be selectable.
Re: [2005] Only enable 1 column in dataGridview?
Just set SelectionMode to FullRowSelect, then get the value from the first column in all the selected rows.
Re: [2005] Only enable 1 column in dataGridview?
Cheers JMC,
I did it using this for anyone else learning it who might find it useful in the future:
vb Code:
For Each itm As DataGridViewRow In Me.DataGridView1.SelectedRows
Me.ListBox1.Items.Add(Me.DataGridView1.Item(0, itm.Index).Value.ToString)
Next