Hello,
i have a question regarding the System::Windows::Forms::ListView. There's a bug witch i can't get rid of.
The intention was to create a ListView item whose last column adjusts to the available space of the surrounding panel. Please check the following code:
Form1.h:
#pragma once
#include "MDIChild.h"
namespace ListView_Test {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
MDIChild ^ child = gcnew MDIChild();
child->MdiParent=this;
child->Show();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private:
System::ComponentModel::Container ^components;
void InitializeComponent(void)
{
this->SuspendLayout();
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(1060, 484);
this->IsMdiContainer = true;
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
}
};
}
MDIChild.h:
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace ListView_Test {
public ref class MDIChild : public System::Windows::Forms::Form
{
public:
MDIChild(void)
{
InitializeComponent();
}
protected:
~MDIChild()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::ListView^ listView1;
private: System::Windows::Forms::ColumnHeader^ columnHeader1;
private: System::Windows::Forms::ColumnHeader^ columnHeader2;
private: System::Windows::Forms::ColumnHeader^ columnHeader3;
private: System::Windows::Forms::ColumnHeader^ columnHeader4;
private: System::Windows::Forms::ColumnHeader^ columnHeader5;
private: System::Windows::Forms::ColumnHeader^ columnHeader6;
private: System::Windows::Forms::ColumnHeader^ columnHeader7;
private: System::Windows::Forms::ColumnHeader^ columnHeader8;
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
System::Windows::Forms::ListViewItem^ listViewItem1 = (gcnew System::Windows::Forms::ListViewItem(gcnew cli::array< System::String^ >(9) {L"1",
L"a", L"b", L"c", L"d", L"e", L"f", L"g", L"h"}, -1));
System::Windows::Forms::ListViewItem^ listViewItem2 = (gcnew System::Windows::Forms::ListViewItem(gcnew cli::array< System::String^ >(9) {L"2",
L"b", L"c", L"d", L"e", L"f", L"g", L"h", L"i"}, -1));
System::Windows::Forms::ListViewItem^ listViewItem3 = (gcnew System::Windows::Forms::ListViewItem(gcnew cli::array< System::String^ >(9) {L"3",
L"c", L"d", L"e", L"f", L"g", L"h", L"i", L"j"}, -1));
System::Windows::Forms::ListViewItem^ listViewItem4 = (gcnew System::Windows::Forms::ListViewItem(gcnew cli::array< System::String^ >(9) {L"4",
L"d", L"e", L"f", L"g", L"h", L"i", L"j", L"k"}, -1));
System::Windows::Forms::ListViewItem^ listViewItem5 = (gcnew System::Windows::Forms::ListViewItem(gcnew cli::array< System::String^ >(9) {L"5",
L"e", L"f", L"g", L"h", L"i", L"j", L"k", L"l"}, -1));
System::Windows::Forms::ListViewItem^ listViewItem6 = (gcnew System::Windows::Forms::ListViewItem(gcnew cli::array< System::String^ >(9) {L"6",
L"f", L"g", L"h", L"i", L"j", L"k", L"l", L"m"}, -1));
System::Windows::Forms::ListViewItem^ listViewItem7 = (gcnew System::Windows::Forms::ListViewItem(gcnew cli::array< System::String^ >(9) {L"7",
L"g", L"h", L"i", L"j", L"k", L"l", L"m", L"n"}, -1));
System::Windows::Forms::ListViewItem^ listViewItem8 = (gcnew System::Windows::Forms::ListViewItem(gcnew cli::array< System::String^ >(9) {L"8",
L"h", L"i", L"j", L"k", L"l", L"m", L"n", L"o"}, -1));
System::Windows::Forms::ListViewItem^ listViewItem9 = (gcnew System::Windows::Forms::ListViewItem(gcnew cli::array< System::String^ >(9) {L"9",
L"i", L"j", L"k", L"l", L"m", L"n", L"o", L"p"}, -1));
System::Windows::Forms::ListViewItem^ listViewItem10 = (gcnew System::Windows::Forms::ListViewItem(gcnew cli::array< System::String^ >(9) {L"0",
L"j", L"k", L"l", L"m", L"n", L"o", L"p", L"q"}, -1));
this->listView1 = (gcnew System::Windows::Forms::ListView());
this->columnHeader1 = (gcnew System::Windows::Forms::ColumnHeader());
this->columnHeader2 = (gcnew System::Windows::Forms::ColumnHeader());
this->columnHeader3 = (gcnew System::Windows::Forms::ColumnHeader());
this->columnHeader4 = (gcnew System::Windows::Forms::ColumnHeader());
this->columnHeader5 = (gcnew System::Windows::Forms::ColumnHeader());
this->columnHeader6 = (gcnew System::Windows::Forms::ColumnHeader());
this->columnHeader7 = (gcnew System::Windows::Forms::ColumnHeader());
this->columnHeader8 = (gcnew System::Windows::Forms::ColumnHeader());
this->SuspendLayout();
this->listView1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
| System::Windows::Forms::AnchorStyles::Left)
| System::Windows::Forms::AnchorStyles::Right));
this->listView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::ColumnHeader^ >(8) {this->columnHeader1, this->columnHeader2,
this->columnHeader3, this->columnHeader4, this->columnHeader5, this->columnHeader6, this->columnHeader7, this->columnHeader8});
this->listView1->FullRowSelect = true;
this->listView1->HeaderStyle = System::Windows::Forms::ColumnHeaderStyle::Nonclickable;
this->listView1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ListViewItem^ >(10) {listViewItem1, listViewItem2,
listViewItem3, listViewItem4, listViewItem5, listViewItem6, listViewItem7, listViewItem8, listViewItem9, listViewItem10});
this->listView1->Location = System::Drawing::Point(6, 15);
this->listView1->Name = L"listView1";
this->listView1->Size = System::Drawing::Size(710, 110);
this->listView1->TabIndex = 2;
this->listView1->UseCompatibleStateImageBehavior = false;
this->listView1->View = System::Windows::Forms::View::Details;
this->listView1->SizeChanged += gcnew System::EventHandler(this, &MDIChild::ResizeListView);
this->columnHeader1->Text = L"Main";
this->columnHeader2->Text = L"Sub1";
this->columnHeader3->Text = L"Sub2";
this->columnHeader4->Text = L"Sub3";
this->columnHeader5->Text = L"Sub4";
this->columnHeader6->Text = L"Sub5";
this->columnHeader7->Text = L"Sub6";
this->columnHeader8->Text = L"Sub7";
this->columnHeader8->Width = 55;
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(721, 139);
this->Controls->Add(this->listView1);
this->Name = L"MDIChild";
this->Text = L"MDIChild";
this->ResumeLayout(false);
}
#pragma endregion
void ResizeListView(System::Object ^ sender, System::EventArgs ^ e)
{
try
{
ListView ^ list = listView1;
int nSize = 3;
int nLastIndex = 7;
int nLastColumnSize;
nSize += list->Columns[0]->Width;
nSize += list->Columns[1]->Width;
nSize += list->Columns[2]->Width;
nSize += list->Columns[3]->Width;
nSize += list->Columns[4]->Width;
nSize += list->Columns[5]->Width;
nSize += list->Columns[6]->Width;
nLastColumnSize = 200;
nSize = list->ClientRectangle.Width - nSize - 19;
if (nSize > nLastColumnSize)
{
nLastColumnSize = nSize;
}
list->Columns[nLastIndex]->Width = nLastColumnSize;
}
catch(...)
{
;
}
}
};
}
As you can see an outer panel(Form1) serves as an MDI container for the interior(MDIChild) which contains the list view.
But if a list view item is displayed, witch content encompasses so many lines that the vertical scroll bar appears, a interessting repaint error arises when maximizing. But only if the ListView was scrolled down bevor the maximize. Presumably it happens because i set the size of the last column header, while the list view is redrawn.
Reproduction:
1.Execute the code posted above.
2.Move the vertical scroll bar of the "MDIChild" window to the bottom.
3.(optional) maximize the Form1.
4.The MDIChild maximize window.
Symptoms:
First, no line is displayed. If we try to mark some lines with a marking-rectangle, it is noticeable that they will not appear until you move the mouse over them. But at the wrong place. They seem to be moved downwards exactly of the height of the non-maximized panel. Even after you press the minimize button, the rows remain initially disappeared, until you move the scroll bar to the bottom.
Additionally a horizontal scroll bar is present, which is, compared to the size of the list view, much to wide. When you move it to the right side, the scroll bar is reduced to the proper width.
Can anyone help me with this problem? -In appendix there is a screenshot showing the problem.
Sincerely,
Michael
|