CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2017
    Posts
    1

    Question Connect listBox1 to accdb (MS Access DB)

    Hi
    Thank you for taking the time to review my issue. I think I have this pretty much setup however I am having trouble connecting my script to the access database I made. I am rather new and I have been looking through YouTube Videos and doing quite a bit of googling. My dev enviroment is Visual Studio 2017 and I do have pretty much everything setup, now its getting everything connected. Let me explain my project.

    Project Idea : Build a simple application that will show 300+ applications in a window. When the user opens this application they are presented with all the applications available. The user will be able to highlight what application they would like to install and click the install button. The application begins its installation process.

    What have I done so far?
    1 Designed the windows form in a very basic manner as shown in the screenshot below



    2 I have gone into MS ACCESS 2016 and designed the data tables which is only 1 table containing 3 fields. Field 1 is the only field that should be presented in the application since this is the field with the application names

    3 I have connected the DB file to Visual Studio 2017 and ready to present the Field1 to the listBox1 in my application

    Below is a screenshot of the concept of the final product of what it SHOULD look like when its done.


    4 I have provided a screenshot of the successful DB connection


    Help is appreciated on moving forward... Finally my code is below...

    Code:
    #pragma once
    
    namespace Project1 {
    
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    
    	/// <summary>
    	/// Summary for MyForm
    	/// </summary>
    	public ref class MyForm : public System::Windows::Forms::Form
    	{
    	public:
    		MyForm(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    		}
    
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~MyForm()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::ListBox^  listBox1;
    	protected:
    	private: System::Windows::Forms::Button^  button1;
    	private: System::Windows::Forms::Button^  button2;
    	private: System::Windows::Forms::Button^  button3;
    	private: System::Windows::Forms::Button^  button4;
    	private: System::Windows::Forms::MenuStrip^  menuStrip1;
    	private: System::Windows::Forms::ToolStripMenuItem^  fileToolStripMenuItem;
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::Label^  label1;
    	private: System::Windows::Forms::ToolStripMenuItem^  openToolStripMenuItem;
    	private: System::Windows::Forms::ToolStripMenuItem^  closeToolStripMenuItem;
    
    	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->listBox1 = (gcnew System::Windows::Forms::ListBox());
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->button2 = (gcnew System::Windows::Forms::Button());
    			this->button3 = (gcnew System::Windows::Forms::Button());
    			this->button4 = (gcnew System::Windows::Forms::Button());
    			this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
    			this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->openToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->closeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->label1 = (gcnew System::Windows::Forms::Label());
    			this->menuStrip1->SuspendLayout();
    			this->SuspendLayout();
    			// 
    			// listBox1
    			// 
    			this->listBox1->FormattingEnabled = true;
    			this->listBox1->Location = System::Drawing::Point(7, 35);
    			this->listBox1->Name = L"listBox1";
    			this->listBox1->Size = System::Drawing::Size(437, 433);
    			this->listBox1->TabIndex = 0;
    			this->listBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &MyForm::listBox1_SelectedIndexChanged);
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(7, 474);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(84, 27);
    			this->button1->TabIndex = 1;
    			this->button1->Text = L"Install";
    			this->button1->UseVisualStyleBackColor = true;
    			// 
    			// button2
    			// 
    			this->button2->Location = System::Drawing::Point(126, 475);
    			this->button2->Name = L"button2";
    			this->button2->Size = System::Drawing::Size(84, 26);
    			this->button2->TabIndex = 2;
    			this->button2->Text = L"Update";
    			this->button2->UseVisualStyleBackColor = true;
    			// 
    			// button3
    			// 
    			this->button3->Location = System::Drawing::Point(245, 475);
    			this->button3->Name = L"button3";
    			this->button3->Size = System::Drawing::Size(84, 26);
    			this->button3->TabIndex = 3;
    			this->button3->Text = L"Uninstall";
    			this->button3->UseVisualStyleBackColor = true;
    			this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
    			// 
    			// button4
    			// 
    			this->button4->Location = System::Drawing::Point(360, 474);
    			this->button4->Name = L"button4";
    			this->button4->Size = System::Drawing::Size(84, 25);
    			this->button4->TabIndex = 4;
    			this->button4->Text = L"Exit";
    			this->button4->UseVisualStyleBackColor = true;
    			this->button4->Click += gcnew System::EventHandler(this, &MyForm::button4_Click);
    			// 
    			// menuStrip1
    			// 
    			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) { this->fileToolStripMenuItem });
    			this->menuStrip1->Location = System::Drawing::Point(0, 0);
    			this->menuStrip1->Name = L"menuStrip1";
    			this->menuStrip1->Size = System::Drawing::Size(450, 24);
    			this->menuStrip1->TabIndex = 5;
    			this->menuStrip1->Text = L"menuStrip1";
    			// 
    			// fileToolStripMenuItem
    			// 
    			this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {
    				this->openToolStripMenuItem,
    					this->closeToolStripMenuItem
    			});
    			this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
    			this->fileToolStripMenuItem->Size = System::Drawing::Size(37, 20);
    			this->fileToolStripMenuItem->Text = L"File";
    			// 
    			// openToolStripMenuItem
    			// 
    			this->openToolStripMenuItem->Name = L"openToolStripMenuItem";
    			this->openToolStripMenuItem->Size = System::Drawing::Size(103, 22);
    			this->openToolStripMenuItem->Text = L"Open";
    			// 
    			// closeToolStripMenuItem
    			// 
    			this->closeToolStripMenuItem->Name = L"closeToolStripMenuItem";
    			this->closeToolStripMenuItem->Size = System::Drawing::Size(103, 22);
    			this->closeToolStripMenuItem->Text = L"Close";
    			this->closeToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::closeToolStripMenuItem_Click);
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(277, 8);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(167, 20);
    			this->textBox1->TabIndex = 6;
    			// 
    			// label1
    			// 
    			this->label1->AutoSize = true;
    			this->label1->Location = System::Drawing::Point(175, 11);
    			this->label1->Name = L"label1";
    			this->label1->Size = System::Drawing::Size(101, 13);
    			this->label1->TabIndex = 7;
    			this->label1->Text = L"Search Applications";
    			this->label1->Click += gcnew System::EventHandler(this, &MyForm::label1_Click);
    			// 
    			// MyForm
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(450, 510);
    			this->Controls->Add(this->label1);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->button4);
    			this->Controls->Add(this->button3);
    			this->Controls->Add(this->button2);
    			this->Controls->Add(this->button1);
    			this->Controls->Add(this->listBox1);
    			this->Controls->Add(this->menuStrip1);
    			this->MainMenuStrip = this->menuStrip1;
    			this->Name = L"MyForm";
    			this->Text = L"Application Installer v1.0";
    			this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
    			this->menuStrip1->ResumeLayout(false);
    			this->menuStrip1->PerformLayout();
    			this->ResumeLayout(false);
    			this->PerformLayout();
    
    		}
    #pragma endregion
    	private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
    	}
    	private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
    		Close();
    	}
    private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
    }
    private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
    }
    private: System::Void closeToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
    	Close();
    }
    private: System::Void listBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
    }
    };
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Connect listBox1 to accdb (MS Access DB)

    The code you've posted is not a native VC++ one. It looks like a managed C++.
    So I move it to the corresponding Forum.
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured