Solved

How to read column of Data grid view in vb.net and find a cell value.

Posted on 2013-05-09
2
611 Views
Last Modified: 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

 Try
            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
                con.Open()
            End If


            da1 = New SqlDataAdapter(s1, con)
            dt1 = New DataTable()
            da1.Fill(dt1)
            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


            Next



        Catch ex As Exception
            MsgBox("Error occured : " & ex.ToString())
        Finally
            con.Close()

        End Try
0
Comment
Question by:searchsanjaysharma
2 Comments
 
LVL 12

Accepted Solution

by:
funwithdotnet earned 500 total points
Comment Utility
Perhaps something like this:

If row.Cells(3).Value = "D"
  row.ReadOnly = True
End If

Open in new window

0
 

Author Closing Comment

by:searchsanjaysharma
Comment Utility
tx
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now