DataGridView - Differnt Column Widths

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roger

    DataGridView - Differnt Column Widths

    I am trying to do a 'simple' task in a DGV control.
    The problem is this.
    I have an unbound DGV with all 'AllowUser' options disabled.
    RowHeader.Visib le=False
    ColumnHeader.Te xt is labelled as needed.
    For simplicity the DGV has 7 columns and 15 rows.
    The 15 rows are populated and the DGV is made visible.
    Everything is just fine.
    But now I want rows 6,7 and 11,12 to have different column spacing to the
    other rows.
    I have not been able to find a way.
    I tried hanlding the DGV.CellFormatt ing Event but cant get the desired
    results.
    In other words I want one DGV control to have different column widths
    depending on row number?

    Can anyone out there help?

    Thanks

    --
    Roger
  • RobinS

    #2
    Re: DataGridView - Differnt Column Widths

    You can't do this with the DataGridView control.

    And please don't multi-post. If you want to post the same
    message to more than one group, please post them all at
    the same time, so if someone in one group provides a
    solution, people in the other groups can see it and choose
    to help someone else.

    Thanks.
    Robin S.
    ---------------------------
    "Roger" <Roger@discussi ons.microsoft.c omwrote in message
    news:55FD9521-03CA-4843-A14F-85CD90B5CD74@mi crosoft.com...
    >I am trying to do a 'simple' task in a DGV control.
    The problem is this.
    I have an unbound DGV with all 'AllowUser' options disabled.
    RowHeader.Visib le=False
    ColumnHeader.Te xt is labelled as needed.
    For simplicity the DGV has 7 columns and 15 rows.
    The 15 rows are populated and the DGV is made visible.
    Everything is just fine.
    But now I want rows 6,7 and 11,12 to have different column spacing to the
    other rows.
    I have not been able to find a way.
    I tried hanlding the DGV.CellFormatt ing Event but cant get the desired
    results.
    In other words I want one DGV control to have different column widths
    depending on row number?
    >
    Can anyone out there help?
    >
    Thanks
    >
    --
    Roger

    Comment

    • Walter Harris

      #3
      RE: DataGridView - Differnt Column Widths

      You can set up a Style and apply your settings to it. Then you apply the
      Style to the Datagrid.

      in my function where setting up the dgv, I use:
      dgvAll.TableSty les.Add(createS tyle());

      where createStyle() =
      //*************** *************** **
      //* Define Style and pass back as a Style
      //*************** *************** **
      private DataGridTableSt yle createStyle() {
      // Define a table style layout and bind
      DataGridTableSt yle myStyle = new DataGridTableSt yle();
      myStyle.Mapping Name = "Project";
      myStyle.BackCol or = Color.LightGree n;
      myStyle.Alterna tingBackColor = Color.LightYell ow;
      myStyle.Selecti onForeColor = Color.DarkGray;

      // Definitions
      DataGridTextBox Column bpuType = new DataGridTextBox Column();
      DataGridTextBox Column stockCode = new DataGridTextBox Column();
      DataGridTextBox Column puCode = new DataGridTextBox Column();

      // Mapping Name
      bpuType.Mapping Name = "BPU_TYPE";
      stockCode.Mappi ngName = "STOCK_CODE ";
      puCode.MappingN ame = "PU_CODE";

      // Header
      bpuType.HeaderT ext = "BPU TYPE ";
      stockCode.Heade rText = "STOCK CODE ";
      puCode.HeaderTe xt = "PU CODE ";

      // Special cases
      bpuType.NullTex t = " ";

      // Alignment and Width (if not default)
      bpuType.Width = 70;
      puCode.Width = 100;
      bpuType.Alignme nt = HorizontalAlign ment.Right;

      // Add to theme
      myStyle.GridCol umnStyles.Add(b puType);
      myStyle.GridCol umnStyles.Add(b usCategory);
      myStyle.GridCol umnStyles.Add(p uCode);

      return myStyle;
      }

      "Roger" wrote:
      I am trying to do a 'simple' task in a DGV control.
      The problem is this.
      I have an unbound DGV with all 'AllowUser' options disabled.
      RowHeader.Visib le=False
      ColumnHeader.Te xt is labelled as needed.
      For simplicity the DGV has 7 columns and 15 rows.
      The 15 rows are populated and the DGV is made visible.
      Everything is just fine.
      But now I want rows 6,7 and 11,12 to have different column spacing to the
      other rows.
      I have not been able to find a way.
      I tried hanlding the DGV.CellFormatt ing Event but cant get the desired
      results.
      In other words I want one DGV control to have different column widths
      depending on row number?
      >
      Can anyone out there help?
      >
      Thanks
      >
      --
      Roger

      Comment

      • RobinS

        #4
        Re: DataGridView - Differnt Column Widths

        This is pretty spiffy, and I'm going to store it away for future use.

        But I think what he wants is the *same* column to have *different*
        widths depending on the row. Is that possible? I didn't think so,
        but if I'm wrong, I'd love to see the code. Unless the code
        below does that, and I'm just not reading it correctly.

        Robin S.
        ---------------------------
        "Walter Harris" <WalterHarris@d iscussions.micr osoft.comwrote in message
        news:7436D5DD-76B6-4C10-BB44-E84FBBB77D51@mi crosoft.com...
        You can set up a Style and apply your settings to it. Then you apply the
        Style to the Datagrid.
        >
        in my function where setting up the dgv, I use:
        dgvAll.TableSty les.Add(createS tyle());
        >
        where createStyle() =
        //*************** *************** **
        //* Define Style and pass back as a Style
        //*************** *************** **
        private DataGridTableSt yle createStyle() {
        // Define a table style layout and bind
        DataGridTableSt yle myStyle = new DataGridTableSt yle();
        myStyle.Mapping Name = "Project";
        myStyle.BackCol or = Color.LightGree n;
        myStyle.Alterna tingBackColor = Color.LightYell ow;
        myStyle.Selecti onForeColor = Color.DarkGray;
        >
        // Definitions
        DataGridTextBox Column bpuType = new DataGridTextBox Column();
        DataGridTextBox Column stockCode = new DataGridTextBox Column();
        DataGridTextBox Column puCode = new DataGridTextBox Column();
        >
        // Mapping Name
        bpuType.Mapping Name = "BPU_TYPE";
        stockCode.Mappi ngName = "STOCK_CODE ";
        puCode.MappingN ame = "PU_CODE";
        >
        // Header
        bpuType.HeaderT ext = "BPU TYPE ";
        stockCode.Heade rText = "STOCK CODE ";
        puCode.HeaderTe xt = "PU CODE ";
        >
        // Special cases
        bpuType.NullTex t = " ";
        >
        // Alignment and Width (if not default)
        bpuType.Width = 70;
        puCode.Width = 100;
        bpuType.Alignme nt = HorizontalAlign ment.Right;
        >
        // Add to theme
        myStyle.GridCol umnStyles.Add(b puType);
        myStyle.GridCol umnStyles.Add(b usCategory);
        myStyle.GridCol umnStyles.Add(p uCode);
        >
        return myStyle;
        }
        >
        "Roger" wrote:
        >
        >I am trying to do a 'simple' task in a DGV control.
        >The problem is this.
        >I have an unbound DGV with all 'AllowUser' options disabled.
        >RowHeader.Visi ble=False
        >ColumnHeader.T ext is labelled as needed.
        >For simplicity the DGV has 7 columns and 15 rows.
        >The 15 rows are populated and the DGV is made visible.
        >Everything is just fine.
        >But now I want rows 6,7 and 11,12 to have different column spacing to the
        >other rows.
        >I have not been able to find a way.
        >I tried hanlding the DGV.CellFormatt ing Event but cant get the desired
        >results.
        >In other words I want one DGV control to have different column widths
        >depending on row number?
        >>
        >Can anyone out there help?
        >>
        >Thanks
        >>
        >--
        >Roger

        Comment

        • Walter Harris

          #5
          Re: DataGridView - Differnt Column Widths

          Hmmm... didn't catch that (doh)

          If what you're reading is correct, he wants to "merge" cells like Excel can
          do. I don't think the DataGrid can actually do that by itself, but I'm not
          100% positive that it can't -- I've NEVER even THOUGHT of trying that.

          Thanks for compliment... no this just sets each column a certain width, not
          a cell...
          This is pretty spiffy, and I'm going to store it away for future use.
          >
          But I think what he wants is the *same* column to have *different*
          widths depending on the row. Is that possible? I didn't think so,
          but if I'm wrong, I'd love to see the code. Unless the code
          below does that, and I'm just not reading it correctly.
          >
          Robin S.
          ---------------------------

          Comment

          • RobinS

            #6
            Re: DataGridView - Differnt Column Widths

            It's okay, it was still nice of you to provide that excellent example
            for the rest of us.

            It doesn't even sound like he wants to merge cells, he just wants
            the columns to be different widths. I guess merging cells is sort
            of one way to accomplish that.

            I know you can make it appear as if the column has a merged
            cell by making the line between two cells disappear (I've done
            it between rows, so I'm assuming it would work between two
            columns), but that still doesn't make one larger like the
            MergeCells in Excel.

            Maybe the original poster will elaborate on his requirements...

            Robin S.
            ----------------------------
            "Walter Harris" <WalterHarris@d iscussions.micr osoft.comwrote in message
            news:D3CD4DE2-8B19-4216-B631-29EB9877664F@mi crosoft.com...
            Hmmm... didn't catch that (doh)
            >
            If what you're reading is correct, he wants to "merge" cells like Excel
            can
            do. I don't think the DataGrid can actually do that by itself, but I'm
            not
            100% positive that it can't -- I've NEVER even THOUGHT of trying that.
            >
            Thanks for compliment... no this just sets each column a certain width,
            not
            a cell...
            >
            >This is pretty spiffy, and I'm going to store it away for future use.
            >>
            >But I think what he wants is the *same* column to have *different*
            >widths depending on the row. Is that possible? I didn't think so,
            >but if I'm wrong, I'd love to see the code. Unless the code
            >below does that, and I'm just not reading it correctly.
            >>
            >Robin S.
            >---------------------------

            Comment

            Working...