Click here to Skip to main content
11,922,026 members (57,362 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
Good day,

I created a tabcontrol that has more than two tabpages, in each of the tabpages, i have a datagrid except the first page.
I have populated the datagrid successfully. The problem is when i click to view the 2nd tab page, the content of the datagrid will display well but on the 3rd tabpage, the content of the datagrid will not be visible (the text is white in color), that is the datagrid on the 3rd tabpage will be populated with data but the content is white in color thereby it's kinda invisible.

here is my code:

tab click event:

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

        If TabControl1.SelectedIndex = 5 Then
            'load symptoms
            'load patient diagnosis history

            'show doc name
            txtDoc.Text = mqhModule.docName
        ElseIf TabControl1.SelectedIndex = 6 Then

            'load prescription history
            'load drugs
            'show doc name
            txtDrugsBy.Text = mqhModule.docName
        End If
    End Sub

code to populate datagrid:

Private Sub loadprescription(ByRef patID As String)

            'retrieve patient info
            'retrieve patient info
            'open database

            'get first student name list from database
            Dim StrSQL As New SqlDataAdapter("SELECT drugs,medicine,dura,dosage,freq,drugInstruction " & _
                                                "presTime,presDate,prescribeby " & _
                                             " FROM patientprescription WHERE patientID='" & patID & "'  ", conMod.Con)
            Dim DR As New DataSet
            Dim usertable As DataTable = DR.Tables(0)


            'datasource of the datagrid
            DGridPres.DataSource = usertable

            'change the data grid column name
            DGridPres.Columns(0).HeaderText = "Medication"
            DGridPres.Columns(1).HeaderText = "Drug"
            DGridPres.Columns(2).HeaderText = "Duration"
            DGridPres.Columns(3).HeaderText = "Dosage"
            DGridPres.Columns(4).HeaderText = "Frquency"
            DGridPres.Columns(5).HeaderText = "Instruction"
            DGridPres.Columns(6).HeaderText = "Time"
            DGridPres.Columns(7).HeaderText = "Date"
            DGridPres.Columns(8).HeaderText = "Prescribed-By"

            'close database
            'catch exception
        Catch ex As Exception
            'dsplay message
            Dim mymsg As New myMsgbox
            With mymsg
                .txtError.Text = "Error! Could not retrieve Patient prescription Information."
            End With
        End Try

    End Sub 
Posted 17-Mar-13 10:54am
Edited 17-Mar-13 11:14am
Maciej Los 17-Mar-13 16:08pm
Please, use "Improve question" widget to update your question.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hey what's probably happening here is your not setting the DataPropertyName property of each individual column of the grid to the field returned by the SQL query, I.e Medication - medicine, Drug -drugs etc...

tarhex 17-Mar-13 16:47pm
it normally works for me if i program it as it is above, i suspect there is a kinda undocumented problem with tab control with data grid
Mickt1985 17-Mar-13 16:49pm
Have you got AutogenerateColumns set to true or false?
tarhex 18-Mar-13 4:33am
I did that and nothing happened. How can i post a picture so that you can see the columns. thanks for help so far.
Mickt1985 18-Mar-13 5:13am
Hey in design view click on the little triangle at the top right of the datagrid, go to Edit Columns and check that the DataPropertyName is set for each individual column.
tarhex 18-Mar-13 5:37am
The columns are loaded dynamically.
tarhex 18-Mar-13 5:39am
Here is the picture of the datagrid
Mickt1985 18-Mar-13 5:52am
That is very strange, it looks like you grid is disabled so try setting that to enabled, failing that what I can suggest you do is after you set the datasource in the code behind do something like this if (dataGridView1.Rows.Count > 0)
dataGridView1.Rows[index].DefaultCellStyle.Font = new System.Drawing.Font("Arial", 10, FontStyle.Bold);
dataGridView1.DefaultCellStyle.SelectionForeColor = System.Drawing.Color.Black;
Mickt1985 18-Mar-13 6:01am
vb version sorry If dataGridView1.Rows.Count > 0 Then
dataGridView1.Rows(index).DefaultCellStyle.Font = New System.Drawing.Font("Arial", 10, FontStyle.Bold)
dataGridView1.DefaultCellStyle.SelectionForeColor = System.Drawing.Color.Black
End If
tarhex 18-Mar-13 6:13am
Trying that now. Thanks for your time so far.
tarhex 18-Mar-13 6:34am
tried it, nothing happened, it still the same.
Mickt1985 18-Mar-13 6:48am
HAve you tried enabling the tabpage. Like tabPage3.Enabled = true?
tarhex 18-Mar-13 7:13am
Big Bro, i finally got it done. Although i can't still figure what really went wrong or explain it. What i did is to recreate a new tabpage and i left the default name (tabpage1) but just changed the text to desirable name. I also created a new datagrid and it did the magic. Thanks bro, i really appreciate.
Mickt1985 18-Mar-13 7:35am
Good stuff, glad you got it sorted.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Just putting this down for those who are having this kind of problem or those who don't know what the problem is when they encounter it. You will mainly encounter this problem when you put the datagrid on a groupbox that is in a tabpage and you make the groupbox background colour transparent. To solve this problem, remove the datagrid from the groupbox.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 568
1 Dave Kreskowiak 285
2 Sergey Alexandrovich Kryukov 173
3 Richard MacCutchan 155
4 ppolymorphe 135
0 OriginalGriff 7,036
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,286
3 George Jonsson 2,840
4 Suvendu Shekhar Giri 2,216

Advertise | Privacy | Mobile
Web04 | 2.8.151120.1 | Last Updated 23 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100