Results 1 to 13 of 13

Thread: [RESOLVED] Format Grid Column Headers

  1. #1
    Fanatic Member
    Join Date
    Aug 05
    Location
    Wisconsin
    Posts
    765

    Resolved [RESOLVED] Format Grid Column Headers

    This code is not formatting the headers?
    Code:
            private void SetUpHoldTableStyles()
            {
                DataGridTableStyle ts = new DataGridTableStyle();
                ts.MappingName = binding2.DataMember.ToString();
    
                DataGridColumnStyle recordid = new DataGridTextBoxColumn();
                recordid.MappingName = "RecordID";                          //column 0
                recordid.HeaderText = "#";
                recordid.Width = -1;
                ts.GridColumnStyles.Add(recordid);
    
                DataGridColumnStyle customername = new DataGridTextBoxColumn();
                customername.MappingName = "CustomerName";
                customername.HeaderText = "Name";
                customername.Width = 100;
                ts.GridColumnStyles.Add(customername);
    
                DataGridColumnStyle checkdate = new DataGridTextBoxColumn();
                checkdate.MappingName = "CheckDate";
                checkdate.HeaderText = "Date";
                checkdate.Width = 20;
                ts.GridColumnStyles.Add(checkdate);
    
                DataGridColumnStyle paymenttype = new DataGridTextBoxColumn();
                paymenttype.MappingName = "PaymentType";                                      
                paymenttype.HeaderText = "#";
                paymenttype.Width = -1;
                ts.GridColumnStyles.Add(paymenttype);
    
                dgHolds.TableStyles.Clear();
                dgHolds.TableStyles.Add(ts);
            }
    It is called from this snippet of code.
    Code:
                DataSet ds = new DataSet();
                ds = client.GetHoldsHeader(strCompanyNum);
                DataTable dt = ds.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    //fill datagrid on the pnlHolds
                    //dgHolds.DataSource = dt.DefaultView;
                    
                    binding2 = new BindingSource();
                    binding2.DataSource = ds;
                    binding2.DataMember = "srmfthdr";
                    dgHolds.DataSource = binding2;
                    SetUpHoldTableStyles();
                }
    There are rows returned and it does execute the SetUpHoldTablesStyles(). Any ideas what I have incorrect?

    THanks

  2. #2
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 03
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    922

    Re: Format Grid Column Headers

    you should call SetUpHoldTableStyles() before setting the datasource. I'm not able to check that right now but that should be the problem.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,794

    Re: Format Grid Column Headers

    Actually, when you define a style, don't you need to tell it which style you want to use? As I understand it, you can define multiple styles, then change the active style by selecting which one you want to use.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  4. #4
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 03
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    922

    Re: Format Grid Column Headers

    Here's a working demo, posted in this same forum.

    techgnome, i think he did define when using
    Code:
                paymenttype.MappingName = "PaymentType";                                      
                ts.GridColumnStyles.Add(paymenttype);
    
    and
    
                dgHolds.TableStyles.Add(ts);
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,794

    Re: Format Grid Column Headers

    right... I get that the style is DEFINED... I see that... but let's say I define and add three styles... how does the grid know which one to use? That was the point I was trying to make.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  6. #6
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 03
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    922

    Re: Format Grid Column Headers

    my bad, i didn't know that you could switch style after displaying the grid and binding the datasource

    one thing i know, if there is one only style, and the MappingName is according to the sql columns name, it will work fine. But only if you set the style before binding data. Else it will be ignored.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  7. #7
    Fanatic Member
    Join Date
    Aug 05
    Location
    Wisconsin
    Posts
    765

    Re: Format Grid Column Headers

    So the two things I need to be doing are:
    1. Set the table style before binding the data
    2. Make sure the tablestyle are mapped using the correct field names? (Is this case sensitive?)

    Thanks........

  8. #8
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 03
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    922

    Re: Format Grid Column Headers

    1 - right
    2 - mandatory; not sure but you should respect upper and lower case.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  9. #9
    Fanatic Member
    Join Date
    Aug 05
    Location
    Wisconsin
    Posts
    765

    Re: Format Grid Column Headers

    Still not working. I went through an made sure everything was spelled and cased correctly, they are. Also am calling the table style set up before. I have this working for a 'new' record. But we need to be able to bring in a 'hold' record to make changes to it before moving the ticket on. When the detail is displayed it still is showing all the fields in the grid, but I want only four to show and with the readable header text...........TDQWERTY I used your sample link to help me build the first grid but the second is not working?

  10. #10
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 03
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    922

    Re: Format Grid Column Headers

    what do you mean by new record?
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  11. #11
    Fanatic Member
    Join Date
    Aug 05
    Location
    Wisconsin
    Posts
    765

    Re: Format Grid Column Headers

    I will post what I changed to make it work when I get bcak to that project.

  12. #12
    Fanatic Member
    Join Date
    Aug 05
    Location
    Wisconsin
    Posts
    765

    Re: Format Grid Column Headers

    I was incorrectly spelling some of the names. The characters were correct but not the Upper/Lower case. Thanks to all for help.

  13. #13
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 03
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    922

    Re: [RESOLVED] Format Grid Column Headers

    Glad it worked out
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •