Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I adapted this code from another thread in order to format my column widths. Now what my datagrid is doing is showing NOTHING, no rows, no columns, splat. I am posting the code in the hopes someone can tell me what I am doing wrong...

 

Dim ds As DataSet = New DataSet
       drRead.Fill(ds, sptable)

       With Me.dgFile
           .DataSource = ds.Tables(sptable)
           .CaptionText = sptable & " Table"
           .Visible = True
           If sptable = "Report_tbl" Then
               .Width = 704
           Else
               .Width = 560
           End If
           .PreferredColumnWidth = 75
       End With

       Dim dgts1 As New DataGridTableStyle
       With dgts1
           .MappingName = sptable
       End With

       Dim grdColumn1 As New DataGridTextBoxColumn
       With grdColumn1
           .Width = 500
       End With

       Dim grdColumn2 As New DataGridTextBoxColumn
       With grdColumn2
           .Width = 2000
       End With

       Dim grdColumn3 As New DataGridTextBoxColumn
       With grdColumn3
           .Width = 800
       End With

       Dim grdColumn4 As New DataGridTextBoxColumn
       With grdColumn4
           .Width = 800
       End With

       Dim grdColumn5 As New DataGridTextBoxColumn
       With grdColumn5
           .Width = 800
       End With

       Dim grdColumn6 As New DataGridTextBoxColumn
       With grdColumn6
           .Width = 800
       End With

       Dim grdColumn7 As New DataGridTextBoxColumn
       With grdColumn6
           .Width = 800
       End With

       Dim cols() As DataGridColumnStyle = {grdColumn1, grdColumn2, grdColumn3, grdColumn4, grdColumn5, grdColumn6, grdColumn7}
       dgts1.GridColumnStyles.AddRange(cols)

       dgFile.TableStyles.Add(dgts1)

       Me.dgFile.Show()

Edited by PlausiblyDamp
Posted (edited)

Maybe there's no result in the Dataset. Have you check the select query used for the Fill method?

 

How about testing your code without using any table styles? That way you'll narrow down the source of the problem into Fill result and binding method.

 

Also try checking the MappingName properties. If I'm not mistaken you should also set the MappingName for the Columns in your TableStyles. I can see in your code that you're simply setting the MappingName for your TableStyles.

Edited by amir100
Amir Syafrudin
Posted

When I comment out this line:

 

dgFile.TableStyles.Add(dgts1)

 

then the table fills. So I don't think it's the dataset.

 

I will look into setting the mapping name for the columns ... any examples ?

 

Thank you, laurie mc

Posted

You were right about the mapping. When I mapped the column to the column name in the SQL Server table, it worked.

 

Dim grdColumn7 As New DataGridTextBoxColumn

With grdColumn7

.MappingName = "DateExpiration"

.HeaderText = "Date Expires"

.Width = 80

End With

dgts1.GridColumnStyles.Add(grdColumn7)

 

I also attached the columns singly to the data grid table style (dgts1) as opposed to a AddRange attach, but I think once I corrected the Mapping Name, it would have still worked.

 

Thanks :o

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...