Datagrid Question in vb.net Using table and Column styles

I am having some trouble getting my windows app to use the table and column styles.  I have provides about the same thing below and I hope you can tell me what is wrong with it:

dsDataSet1   is a dataset
dtDataTble is a datatable
dvDataView1 is a dataView
dgDataGrid1 is a datagrid


dsDataSet1 = SrchDrug()
        dtDataTble = dsDataSet1.Tables(0)
        dvDataView1 = dtDataTble.DefaultView

with dgDataGrid1
  .DataSource = dvDataView1
end with


dgDataGrid1.TableStyles.Clear()

        Dim grdTableStyle1 As New DataGridTableStyle
        With grdTableStyle1
            .MappingName = dvFormulSrch.Table.TableName

        End With
        Dim grdColStyle1 As New DataGridTextBoxColumn
        With grdColStyle1
            .MappingName = "DrugName"
            .HeaderText = "Drug Name"
            .Width = 100
        End With
grdTableStyle1.GridColumnStyles.Add(grdColStyle1)
        Dim grdColStyle2 As New DataGridTextBoxColumn
        With grdColStyle2
            .MappingName = "[B/G]"
            .HeaderText = "B/G"
            .Width = 50
        End With

I did not define all columns either in this question or in my program.
Why won't it show the column format indicated by the styles?
 
garyinmiami2003Asked:
Who is Participating?
 
SanclerConnect With a Mentor Commented:
1)  You clear the datagrid's table styles with

   dgDataGrid1.TableStyles.Clear()

Where do you add the new table style?

2)  You set the datagrid's data source with

   with dgDataGrid1
      .DataSource = dvDataView1
   end with

as dvDataView1.  You set your new table styles MappingName with

        With grdTableStyle1
            .MappingName = dvFormulSrch.Table.TableName
        End With

That is, you refer it to the name of the table of a different dataview - drFormulSrch.  That may turn out to be OK, but it looks odd.

Roger
0
 
Bob LearnedConnect With a Mentor Commented:
You have to get the MappingName properties set exactly to what the field names are from the DataTable.

Bob
0
 
garyinmiami2003Author Commented:
I read the replies tried to apply what you have told me and the problem persists.  This is what I've done.  I set up a test program with a grid.  The grid is populated with a stored procedure that returns only one column.  The actual code of this test (code that shows the grid formating)


 dsFormulSrch = SrchDrug()
        dtFormulSrch = dsFormulSrch.Tables(0)
        dvFormulSrch = dtFormulSrch.DefaultView
        With dgFODrugs
            .DataSource = dvFormulSrch
            '  .DataMember = "FormulSrch"
        End With
        dgFODrugs.TableStyles.Clear()

        Dim grdTableStyle1 As New DataGridTableStyle
        With grdTableStyle1
            .MappingName = dvFormulSrch.Table.TableName

        End With
        Dim grdColStyle1 As New DataGridTextBoxColumn
        With grdColStyle1
            .MappingName = "DrugName"
            .HeaderText = "Drug Name"
            .Width = 200
        End With
        grdTableStyle1.GridColumnStyles.Add(grdColStyle1)




comment:

The grid is being filled but the widening of the column does not take.  While my task isn't this simple, if you can show me what is wrong with the one column, I feel I can carry on.

 
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Bob LearnedCommented:
Can you show me what the DataGrid looks like?

Post a screen shot here:

   http://ee-stuff.com/Expert/Upload/upload.php?qid=<qid>

        or

   http://ee-stuff.com/Expert/Upload/upload.php?qid=21873023

When you upload the screen shot, give me the file id (fid), please.

Bob
 
0
 
garyinmiami2003Author Commented:
I had never added the grdTablestyle.


dgFODrugs.TableStyles.Add(grdTableStyle1)  

Thank you both for the help.

garyinmiami2003
0
 
SanclerCommented:
Try adding this at the end

        dgFODrugs.TableStyles.Add(grdTableStyle1)

Roger

0
 
SanclerCommented:
cross-posting - times two - ;-)

Roger
0
 
garyinmiami2003Author Commented:
Roger:

That was what I was trying to tell you that I did in my comment.  As soon as I added that it worked fine.  Just the way I had it on Friday.  Notice I closed out the question and once again, you have provided fantastic expert advice.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.