Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3222062
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:56:52+00:00 2026-05-17T15:56:52+00:00

I have a Windos::Forms::GroupBox which contains a Windows::Forms::ListView . When I add items, I

  • 0

I have a Windos::Forms::GroupBox which contains a Windows::Forms::ListView. When I add items, I add items to the ListView I tell it to resize but how do I do the same for it’s parent GroupBox?

[edit] This is my custom resizing list control:

ResizingListView::ResizingListView(void)
{

}

void ResizingListView::ResizeVerticallyToItems(void)
{
    // Work out the height of the header
    int headerHeight = 0;
    int itemsHeight = 0;
    if( this->Items->Count == 0 )
    {
        // If no items exist, add one so we can work out how big the header is
        Items->Add("");
        headerHeight = GetHeaderSize();
        this->Items->Clear();
        itemsHeight = 0;
    }
    else
    {
        headerHeight = GetHeaderSize();
        itemsHeight = this->Items->Count*this->Items[0]->Bounds.Height;
    }

    // Work out the overall height and resize to it
    System::Drawing::Size sz = this->Size;
    int borderSize = 0;
    if( this->BorderStyle != System::Windows::Forms::BorderStyle::None )
    {
        borderSize = 2;
    }
    sz.Height = headerHeight+itemsHeight+borderSize;
    this->Size = sz;
}

int ResizingListView::GetHeaderSize(void)
{
    return Items[0]->Bounds.Top;
}

void ResizingListView::OnResize(System::EventArgs^ e)
{
    if( this->Scrollable == false )
    {
        ResizeVerticallyToItems();
    }
}

So when I finish aadding items I call ResizeVerticallyToItems() which resizes the control without any problems. The parent GroupBox has some padding though which disappears when my list resizes. So my thoughts were that I needed to ask the parent GroupBox to resize.

This is the group box’s initialisation:

this->grpMyStatus->AutoSize = true;
this->grpMyStatus->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(64)), 
    static_cast<System::Int32>(static_cast<System::Byte>(64)), static_cast<System::Int32>(static_cast<System::Byte>(64)));
this->grpMyStatus->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
this->grpMyStatus->Controls->Add(this->lstMyStatus);
this->grpMyStatus->Dock = System::Windows::Forms::DockStyle::Top;
this->grpMyStatus->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Bold, 
    System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
this->grpMyStatus->ForeColor = System::Drawing::Color::SkyBlue;
this->grpMyStatus->Location = System::Drawing::Point(3, 166);
this->grpMyStatus->Name = L"grpMyStatus";
this->grpMyStatus->Padding = System::Windows::Forms::Padding(3, 3, 3, 20);
this->grpMyStatus->Size = System::Drawing::Size(270, 92);
this->grpMyStatus->TabIndex = 5;
this->grpMyStatus->TabStop = false;
this->grpMyStatus->Text = L"My Status";

…and this is the child list’s initialisation:

this->lstMyStatus->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(64)), 
    static_cast<System::Int32>(static_cast<System::Byte>(64)), static_cast<System::Int32>(static_cast<System::Byte>(64)));
this->lstMyStatus->BorderStyle = System::Windows::Forms::BorderStyle::None;
this->lstMyStatus->Columns->AddRange(gcnew cli::array< System::Windows::Forms::ColumnHeader^  >(1) {this->columnHeader6});
this->lstMyStatus->Dock = System::Windows::Forms::DockStyle::Top;
this->lstMyStatus->Font = (gcnew System::Drawing::Font(L"Verdana", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
    static_cast<System::Byte>(0)));
this->lstMyStatus->ForeColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(224)), 
    static_cast<System::Int32>(static_cast<System::Byte>(224)), static_cast<System::Int32>(static_cast<System::Byte>(224)));
this->lstMyStatus->HeaderStyle = System::Windows::Forms::ColumnHeaderStyle::None;
this->lstMyStatus->HideSelection = false;
this->lstMyStatus->Items->AddRange(gcnew cli::array< System::Windows::Forms::ListViewItem^  >(3) {listViewItem3, 
    listViewItem4, listViewItem21});
this->lstMyStatus->LabelWrap = false;
this->lstMyStatus->Location = System::Drawing::Point(3, 18);
this->lstMyStatus->Name = L"lstMyStatus";
this->lstMyStatus->RightToLeft = System::Windows::Forms::RightToLeft::Yes;
this->lstMyStatus->RightToLeftLayout = true;
this->lstMyStatus->Scrollable = false;
this->lstMyStatus->ShowGroups = false;
this->lstMyStatus->ShowItemToolTips = true;
this->lstMyStatus->Size = System::Drawing::Size(264, 54);
this->lstMyStatus->SmallImageList = this->imgLights;
this->lstMyStatus->TabIndex = 18;
this->lstMyStatus->UseCompatibleStateImageBehavior = false;
this->lstMyStatus->View = System::Windows::Forms::View::Details;
this->lstMyStatus->SelectedIndexChanged += gcnew System::EventHandler(this, &Status::lstMyStatus_SelectedIndexChanged);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:56:53+00:00Added an answer on May 17, 2026 at 3:56 pm

    It’s automatic when you set the GroupBox’ AutoSize property to True, it will grow as needed to fit the ListView. This isn’t very common in most typical layouts since that will makes it liable to overlap some other control or grow beyond the form edges.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GroupBox control in my Windows Forms application, inside of which I
I have a Windows.Forms.ListView where the user shall be able to add and remove
I have a Windows Forms app that contains a groupbox with about 30 controls.
I have a Windows Forms ListView in a form (C#, VS 2005) and have
I have a Windows Forms application (C#) containing a ListBox into which I have
I have a Windows Forms TextBox in which I want to allow the user
I have a Windows Forms Application which used the WebBrowser class to access a
I have a Windows Forms user control which consists of several controls. Among others
I have a Windows Forms ToolStripSplitButton which shows only an icon. I have added
I have a Windows Forms application that I'm working on, but I'm having trouble

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.