DataGridView ReadOnly rows and columns in VB.NET

The DataGridView control can display rows of data from a data source. You can extend the DataGridView control in a number of ways to build custom behaviors into your applications. The ReadOnly property indicates whether the data displayed by the cell can be edited or not. You can set ReadOnly Property in three levels. You can make entire dataGridView as ReadOnly.

dataGridView1.ReadOnly = true

You can make entire row as ReadOnly

dataGridView1.Rows(index).ReadOnly = true;

You can make entire Column as ReadOnly

dataGridView1.Columns(index).ReadOnly = true;

The following source code shows how to make a row as Readonly in a DataGridView.

Imports System.Data.SqlClient
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        DataGridView1.ColumnCount = 3
        DataGridView1.Columns(0).Name = "Product ID"
        DataGridView1.Columns(1).Name = "Product Name"
        DataGridView1.Columns(2).Name = "Product_Price"

        Dim row As String() = New String() {"1", "Product 1", "1000"}
        row = New String() {"2", "Product 2", "2000"}
        row = New String() {"3", "Product 3", "3000"}
        row = New String() {"4", "Product 4", "4000"}

        DataGridView1.Rows(1).ReadOnly = True

    End Sub
End Class (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About