Solved

Text not visible in DataGridView1 VB.Net 2005

Posted on 2008-10-23
2
218 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Math Equation 23 86
export data table to excel in vb.net 10 26
Help with adding data element is a specific row of an xml file using VB.NET 4 27
VB.NET 2008 - SQL Timeout 9 24
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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 …

773 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