开发者

C++ : How to populate the second column of a listview via code

开发者 https://www.devze.com 2023-02-21 21:06 出处:网络
I have a listview with 2 columns. I can easily populate the first column by using: commandHistory->Items->Add(\"Column 1 Entry S开发者_C百科uccessful!\");

I have a listview with 2 columns. I can easily populate the first column by using:

commandHistory->Items->Add("Column 1 Entry S开发者_C百科uccessful!");

But how would I go about populating the second column at the same time?


Use the SubItems property. Like this:

             ListViewItem^ item = commandHistory->Items->Add("Frist!");
             item->SubItems->Add("2nd column");


You want to use a ListViewItem.

Here's an example:

ListView^ lv = gcnew ListView();
lv->Columns->Add("Language");
lv->Columns->Add("Creator");
ListViewItem^ a = gcnew ListViewItem(gcnew array<String^> { L"C++", L"Stroustrup" });
ListViewItem^ b = gcnew ListViewItem(gcnew array<String^> { L"Java", L"Gosling" });
lv->Items->AddRange(gcnew array<ListViewItem^> { a, b }); 
0

精彩评论

暂无评论...
验证码 换一张
取 消