Click here to Skip to main content
16,016,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

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


        If TabControl1.SelectedIndex = 5 Then

            'load symptoms
            loadSymptomsCmb()

            'load patient diagnosis history
            loadDiagnosisHistory(mqhModule.treatPatID)


            'show doc name
            txtDoc.Text = mqhModule.docName

        ElseIf TabControl1.SelectedIndex = 6 Then


            'load prescription history
            loadprescription(mqhModule.treatPatID)

            'load drugs
            loadDrugsCmb()

            'show doc name
            txtDrugsBy.Text = mqhModule.docName

        End If

    End Sub



code to populate datagrid:

VB
Private Sub loadprescription(ByRef patID As String)



        Try
            'retrieve patient info
            'retrieve patient info

            'open database
            conMod.openDB()


            '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

            StrSQL.Fill(DR)
            StrSQL.Dispose()

            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
            conMod.closeDB()

            '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
Updated 30-May-22 4:55am
v2
Comments
Maciej Los 17-Mar-13 16:08pm    
Please, use "Improve question" widget to update your question.

When the form is loaded.

private void Form_Main_Load(object sender, EventArgs e)
TabMain.SelectedIndex = 2;
TabMain.SelectedIndex = 1;
TabMain.SelectedIndex = 0;

It works fine.
 
Share this answer
 
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...

See http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn_properties.aspx[^]
 
Share this answer
 
Comments
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
frostcox 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.
frostcox 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.
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900