How to read column of Data grid view in vb.net and find a cell value.
Posted on 2013-05-09
I have a datagridview that is binded from data table.
It has 4 columns, UID, SName,FName and IMS.
Few rows in ims column will contain the value as D
I want to read those rows and enable as locked or readonly so that no one is able to fill any text over there.
The blank cells of fields ims, should be fillable.
The code i m using is
con = New SqlConnection("Data Source=xxxxx.xxx.xxx.xxx;Initial Catalog=cusem2;User Id=sa;Password=tomato!@#$otamot")
s1 = "select UID,Sname as 'Name',fname as 'Father',IMS from mstmassstudents where institute='" & CType(cmbinstitutes.SelectedItem, DataRowView)("institute").ToString() & "' and course='" & CType(cmbcourses.SelectedItem, DataRowView)("course").ToString() & "' and subjectcode='" & CType(cmbsubjectcodes.SelectedItem, DataRowView)("subjectcode").ToString() & "' order by 1"
If (con.State = ConnectionState.Closed) Then
da1 = New SqlDataAdapter(s1, con)
dt1 = New DataTable()
DataGridView1.DataSource = dt1
DataGridView1.Visible = True
DataGridView1.AllowUserToAddRows = False
For Each row As DataGridViewRow In DataGridView1.Rows
//How to refer to column ims and make the rows where the ims cell with value as 'D'
to be locked or readonly
Catch ex As Exception
MsgBox("Error occured : " & ex.ToString())