Solved

Text not visible in DataGridView1 VB.Net 2005

Posted on 2008-10-23
2
216 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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

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

11 Experts available now in Live!

Get 1:1 Help Now