Solved

Text not visible in DataGridView1 VB.Net 2005

Posted on 2008-10-23
2
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

730 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