Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > vb.net datagridview
 

vb.net datagridview

we are trying to make certain rows readonly on a datagridview

We have a datagridview control which is bound

on the form load event after the datagrid has been set

we run the following

Dim cnt As Integer
For cnt = 0 To Me.dgvCorr.Rows.Count - 1
If CInt(Me.dgvCorr.Rows(cnt).Cells("disable").Value) = 1 Then
dgvCorr.Rows(cnt).ReadOnly = True
End If
Next

It is going to this code.

Yet the readonly property is not sticking.

I tried putting this code in different places such as form paint

datagridview after binding etc.

Just never works - what should really do.

Thanks,

rustintrans  Friday, April 28, 2006 7:10 PM

Paste this code intothe CellFormatting event handlerofyour DataGridView:

Dim dgv As DataGridView = CType(sender, DataGridView)

If dgv("Disable", e.RowIndex).Value = 1 Then

dgv.Rows(e.RowIndex).ReadOnly = True

End If

vkh75  Friday, April 28, 2006 7:58 PM

Thanks for the suggestion:

I forgot to mention one thing. Our "0" column is bound to a boolean which of course defaults to a check box.

we want to be able to enable and disable the check boxes based on an othercolumn value or from other columns already selected.

The example given is close to what we had (see below)

but I wanted the user to see disabled and enabled check boxes,

What is annoying is the row readonly property set on the load event seems to get lost why?

Private Sub dgvCorr_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles dgvCorr.CellBeginEdit

If CInt(Me.dgvCorr.Rows(e.RowIndex).Cells("disable").Value)= 1 Then

MessageBox.Show("This row can not be selected at this time")

e.Cancel = True

End If

End Sub

rustintrans  Friday, April 28, 2006 8:17 PM

You can use google to search for other answers

Custom Search

More Threads

• Need help creating a category manager, advice on control usage...
• DataGridView DataBinding - SuspendBinding() & ResumeBinding()
• Connection Strings in Machine.Config and Table Adapter?
• parent/child tables in dataset do not show the details of my child table; only shows the master rows
• Disableing a coloumn in a DataGridView
• Multiple DataGridViews Same DataSource Different Filters
• Connect dataset with comboboxdatagridview
• BindingSource Delete/Change
• DataGridView and Heterogenous cell types
• How to validate new DataGridViewRow?