Solved

Text not visible in DataGridView1 VB.Net 2005

Posted on 2008-10-23
2
217 Views
Last Modified: 2012-06-21
The following code collects data from a SQL DB and populates a DataGridView, the only problem is I can't see the data in the DataGridView. If I select a cell then I can see whats in that cell., but I need to see all of the records in the DataGridView rows. The color of the text is white so it's no wonder I can't see it. I have tried to find in the properties of the DataGridView how to fix this problem back I haven't had any luck. There has got to be a way of selecting the text color.

Any help would be appreciated.


Dim MySQLConnection As String = My.Settings.dbConnection
        Dim dbConnection As New SqlConnection
        dbConnection.ConnectionString = MySQLConnection

        Dim bsPatients As BindingSource
        bsPatients = New BindingSource
        dbConnection.Open()
        Dim strSQL As String = "SELECT FirstName, LastName, Address FROM Patient WHERE LastName = '" & LastName.Text & "' ORDER BY FirstName"

        Dim myDA As SqlDataAdapter = New SqlDataAdapter(strSQL, dbConnection)

        'Dim myPatient As DataSet = New DataSet()
        Dim myPatient As DataTable = New DataTable
        myDA.Fill(myPatient)

        bsPatients.DataSource = myPatient
        DataGridView1.DataSource = bsPatients
        dbConnection.Close()
        dbConnection = Nothing

    End Sub
0
Comment
Question by:rfgraham
2 Comments
 
LVL 13

Accepted Solution

by:
SameerJagdale earned 500 total points
ID: 22793627
you have to handle the "RowDataBound Event".


Protected Sub Grid_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

        Dim gridView As GridView = CType(sender,GridView)

        'set colors

        If (e.Row.RowType = DataControlRowType.DataRow) Then

            Dim index As Integer = 0

            Do While (index < GridView.Columns.Count)

                Dim iNumber As Integer = Convert.toInt32(DataBinder.Eval(e.Row.Cells(index)))

                Select Case (iNumber)

                    Case 1

                        e.Row.Cells(index).BackColor = Color.Green

                    Case 2

                        e.Row.Cells(index).BackColor = Color.Yellow

                    Case 3

                        e.Row.Cells(index).BackColor = Color.Red

                End Select

                index = (index + 1)

            Loop

        End If

    End Sub

Open in new window

0
 

Author Comment

by:rfgraham
ID: 22797595
So, there is no way to select text color in the properties of the DataGridView object? I can select foreground, background color but not text color? You wouldn't happen to know why Microsoft developed this object like this would you?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

912 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

24 Experts available now in Live!

Get 1:1 Help Now