Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't display header text in datagrid

Status
Not open for further replies.

mk97

MIS
Oct 16, 2003
3
0
0
US
I have a datagrid called "grEmployeeList" on a form. I can display the data returned by sql. The problem is I can't display customized header text in a datagrid. Can someone tell me what I am doing wrong?

Table "Person" fields--Person_ID, FName, LName, Name_Kanji, Prefix, .....Phone_Number....Membership_Type

Table "Employee_Person" fields --Person_ID, Comp_ID, Title, Employee_Memo, Phone, Extension

CompID = frmSearch.SelectedCompID
---------------------------------------------------
'display employee names in datagrid
strSQL = "SELECT Person.Person_ID, Person.LName, Person.FName, Person.Name_Kanji, Person.Phone_Number FROM Person, Employee_Person WHERE Employee_Person.Comp_ID = " & CompID & "AND Employee_Person.Person_ID = Person.Person_ID"

Dim da As New OleDbDataAdapter(strSQL, cnJBSD)
Dim dsP As New DataSet
da.Fill(dsP)

Dim tblstyle As New DataGridTableStyle
tblstyle.MappingName = "Person"

Dim col1 As New DataGridTextBoxColumn
col1.MappingName = "Person_ID"
col1.HeaderText = "ID"
col1.Alignment = HorizontalAlignment.Center
col1.Width = 60
tblstyle.GridColumnStyles.Add(col1)

Dim col2 As New DataGridTextBoxColumn
col2.MappingName = "LName"
col2.HeaderText = "Last Name"
col2.Alignment = HorizontalAlignment.Center
col2.Width = 60
tblstyle.GridColumnStyles.Add(col2)

Dim col3 As New DataGridTextBoxColumn
col3.MappingName = "FName"
col3.HeaderText = "First Name"
col3.Alignment = HorizontalAlignment.Right
col3.Width = 60
tblstyle.GridColumnStyles.Add(col3)

Dim col4 As New DataGridTextBoxColumn
col4.MappingName = "Name_Kanji"
col4.HeaderText = "Name"
col4.Alignment = HorizontalAlignment.Center
col4.Width = 60
tblstyle.GridColumnStyles.Add(col4)

Dim col5 As New DataGridTextBoxColumn
col5.MappingName = "Phone_Number"
col5.HeaderText = "Phone Number"
col5.Alignment = HorizontalAlignment.Right
col5.Width = 60
tblstyle.GridColumnStyles.Add(col5)

grEmployeeList.TableStyles.Add(tblstyle)
grEmployeeList.DataSource = dsP.Tables(0).DefaultView

----------------------------------------------------------
 
grEmployeeList.ColumnHeadersVisible = True

Try that one...

Dwaine
 
Hi Dwaine,

Column Headers are visible, but the texts I wanted to show were not shown, instead, I had field's names on column headers.

But I figured out my problem. Since I was pulling out data from two tables, I had to name the table in my dataset.

I added/modified these lines.
before filling "da" adapter,
da.TableMappings.Add("Table", "Emp")

Mapping name needs to be "Emp"
tblstyle.MappingName = "Emp"

Specify the name of the table
grEmployeeList.DataSource = dsP.Tables("Emp")

These took care of my problem.
Thank for your suggestion, Dwaine.
 
Oh... got it. I didn't infer that from your original question... I was just going on "I can't display customized header text in a datagrid"

Glad you got it figured out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top