?
Solved

Datagrid Question in vb.net  Using table and Column styles

Posted on 2006-06-02
8
Medium Priority
?
219 Views
Last Modified: 2010-04-23
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?
 
0
Comment
Question by:garyinmiami2003
  • 3
  • 3
  • 2
8 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 1800 total points
ID: 16820702
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
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 200 total points
ID: 16820705
You have to get the MappingName properties set exactly to what the field names are from the DataTable.

Bob
0
 

Author Comment

by:garyinmiami2003
ID: 16832473
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 16832583
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
 

Author Comment

by:garyinmiami2003
ID: 16832585
I had never added the grdTablestyle.


dgFODrugs.TableStyles.Add(grdTableStyle1)  

Thank you both for the help.

garyinmiami2003
0
 
LVL 34

Expert Comment

by:Sancler
ID: 16832601
Try adding this at the end

        dgFODrugs.TableStyles.Add(grdTableStyle1)

Roger

0
 
LVL 34

Expert Comment

by:Sancler
ID: 16832608
cross-posting - times two - ;-)

Roger
0
 

Author Comment

by:garyinmiami2003
ID: 16832637
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question