update listbox??
-
Oops , sorry...
int index = listBox1->Items->Add(String::Concat(someString)); listBox1->SelectedIndex = index; listBox1->Update();
listBox1->SelectedIndex = index; is optional - without it the added items won't automatically scroll into view. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
its scrolling down.. i notice on the scroll bar, its blinking. but the list only visible after its finish scanning :P Do i need to do anything to the form or any other options i need to add ??
hmm it worked for me. I'm assuming you're using Windows Forms for UI, and your code is running on the UI thread... Maybe try an Application::DoEvents(); call after (or instead of) the Update() call.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I'm not sure what you were doing with those string conversions, but if you don't need them, this should work:
wstring directory =(L"C:\\Windows\\system32");
if (ListFiles(directory, L"*", files))
{
for (vector<wstring>::iterator it = files.begin(); it != files.end(); ++it)
{
int index = listBox1->Items->Add(String::Concat(gcnew String(it->c_str())));
listBox1->SelectedIndex = index;
listBox1->Update();
}
}Mark Salsbery Microsoft MVP - Visual C++ :java:
-
well i were collecting the codes there and here, so to match them i keep converting but ur code made it look short and nice :) thanks ya. but the listbox showing the list after complete scanning..
Here's the code I'm testing with - I can see all the items get added...
for (int i = 0; i < 1000; i++) { int index = listBox1->Items->Add(i.ToString()); listBox1->SelectedIndex = index; listBox1->Update(); //Application::DoEvents(); }
Using the Update() or the DoEvents() method yields the same results. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Here's the code I'm testing with - I can see all the items get added...
for (int i = 0; i < 1000; i++) { int index = listBox1->Items->Add(i.ToString()); listBox1->SelectedIndex = index; listBox1->Update(); //Application::DoEvents(); }
Using the Update() or the DoEvents() method yields the same results. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
below is the full coding of my form :-
#pragma once
#include "Mainmenu.h"
#include "Scanner.cpp"using namespace std;
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 trialcpp {
/// <summary> /// Summary for Autoscanner /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> public ref class Autoscanner : public System::Windows::Forms::Form { public: Autoscanner(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~Autoscanner() { if (components) { delete components; } } private: System::Windows::Forms::Label^ label1; private: System::Windows::Forms::Button^ start\_button; private: System::Windows::Forms::Button^ close\_button; protected: private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->start_button = (gcnew System::Windows::Forms::Button());
this->close_button = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_castSystem::Byte(0)));
this->label1->Location = System::Drawing::Point(22, 22);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(176, 16);
this->label1->TabIndex = 0;
this->label1->Text = L"S -
below is the full coding of my form :-
#pragma once
#include "Mainmenu.h"
#include "Scanner.cpp"using namespace std;
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 trialcpp {
/// <summary> /// Summary for Autoscanner /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> public ref class Autoscanner : public System::Windows::Forms::Form { public: Autoscanner(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~Autoscanner() { if (components) { delete components; } } private: System::Windows::Forms::Label^ label1; private: System::Windows::Forms::Button^ start\_button; private: System::Windows::Forms::Button^ close\_button; protected: private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->start_button = (gcnew System::Windows::Forms::Button());
this->close_button = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_castSystem::Byte(0)));
this->label1->Location = System::Drawing::Point(22, 22);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(176, 16);
this->label1->TabIndex = 0;
this->label1->Text = L"SYou need to get rid of the BeginUpdate() and EndUpdate() calls. Those are for when you DON'T want to see the listbox update until all items have been added. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
You need to get rid of the BeginUpdate() and EndUpdate() calls. Those are for when you DON'T want to see the listbox update until all items have been added. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
thanks ya.. its working now... but jus that every file is selected.. but its ok for now.. thanks a lot..
Thilek wrote:
every file is selected
You can handle selection the way you want....I was just using a single-selection control to test. :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Thilek wrote:
every file is selected
You can handle selection the way you want....I was just using a single-selection control to test. :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
okies thanks ya... i try to add string matching function to it but the program exit with error msg :- Managed' has exited with code -1073741819 (0xc0000005). But it works if i scan directory will less files (about 160 files). hm... confusing....