1 / 6

C++/CLI ListBox Controls: SelectionMode, Items, SelectedItem, SelectedIndex, SelectedItems, SelectedIndices

Learn how to use ListBox controls in C++/CLI, including setting selection modes, accessing items and their properties, and handling selection change events. This example demonstrates how to display a collection of values in a scrollable list and how to select and manipulate items.

iolson
Download Presentation

C++/CLI ListBox Controls: SelectionMode, Items, SelectedItem, SelectedIndex, SelectedItems, SelectedIndices

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Controls in C++/CLI (3) • ListBox (Property: SelectionMode, Items, SelectedItem, SelectedIndex, SelectedItems, SelectedIndices; Event: SelectedIndexChanged) • Show a collection of values, each with index, scrollable; • Select one or more items, event • SelectionMode (None, One, MultiSimple, and MultiExtended) • please see http://msdn.microsoft.com/en-us/library/system.windows.forms.selectionmode.aspx

  2. An Example (1) • Draft a design…. • Form1 and myDialog Classes • Variables, methods • Components, event handlers • Collections

  3. An Example (2) • Start from Form1 • Add Label, Text “Name:”, Name “label1” • Add ListBox, Name “nameList”, SelectionMode “one”; • Add three Buttons for “Add”, “Delete” and Edit”; Name bnAdd, bnDelete, bnEdit; add click event handlers, bnAdd_Click, bnDelete_Click, bnEdit_Click; • Add a form for MyDialog • Add Label, Text “Enter Name:”; Add TextBox, Name myTextBox; • Add two buttons for “OK” and “Cancel”, Name as bnOK, bnCancel; add click events of bnOK_Click and bnCancel_Click; Write handler methods; set DialogResult for each; • Set MyDialog’s AcceptButton and CancelButton;

  4. Strings in C++/CLI • http://msdn.microsoft.com/en-us/library/system.string.aspx • public: static String^ Format( String^ format, ... array<Object^>^ args ) • {index[,length][:formatString]} • {0}, {0, 10}, {0, -10}, {0, -10:D6} • May be needed in Project #3

  5. String^ dateString1 = "1"; String^ fmtString = String::Format("{0,10}",dateString1); // -10 to left, 10 to right Console::WriteLine(fmtString); int dateString2 = 1; String^ fmtString = String::Format("{0,-10:D6}",dateString2); Console::WriteLine(fmtString); String^ result = nullptr; result += String::Format("{0,10}", L"X4"); result += String::Format("{0, 10:D6}", dateString2); result += String::Format("{0,10}", L"end"); Console::WriteLine(result);

  6. String^ result1 = L"X4"; String^ result2 = String::Format("{0} ", dateString2); String^ result3 = L"end"; Console::WriteLine("{0,10} {1, 10} {2,10}", result1, result2, result3); fmtString = String::Format("{0,10} {1, 10} {2,10}", result1, result2, result3); Console::WriteLine(fmtString); fmtString = String::Format("{0,10} {1, 10} {2,10}", result1, dateString1, result3); Console::WriteLine(fmtString);

More Related