.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
323 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello
how to add Text and Value to Combobox ?
here my code:
//ComboboxItem.h
namespace I2CProg {
using namespace System;
public ref class ComboboxItem
{
String^ _text = "";
Object^ _value;
public: property String^ Text
{
String^ get()
{
return _text;
}
void set(String^ value)
{
_text = value;
}
}
public: property Object^ Value
{
Object^ get()
{
return _value;
}
void set(Object^ value)
{
_value = value;
}
}
public: String^ ToString() override
{
return Text;
}
};
}
//Main.cpp
#include "MainForm.h"
#include "ComboboxItem.h"
using namespace System;
using namespace System::Windows::Forms;
void MainForm::LoadChipSize()
{
cbx_ChipSize->Items->Clear();
cbx_ChipSize->Items->Add(gcnew ComboboxItem{ Text = "Chip Size", Value = 0 }); //<-- Error C2065 'Value': undeclared identifier and Error C3673 'I2CProg::ComboboxItem': class does not have a copy - constructor
}
the name of combobox is cbx_ChipSize
and here code in MainForm.h
//
private: System::Windows::Forms::ComboBox^ cbx_ChipSize;
//
this->cbx_ChipSize = (gcnew System::Windows::Forms::ComboBox());
// cbx_ChipSize
//
this->cbx_ChipSize->DisplayMember = L"Text";
this->cbx_ChipSize->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
this->cbx_ChipSize->FormattingEnabled = true;
this->cbx_ChipSize->Location = System::Drawing::Point(66, 22);
this->cbx_ChipSize->Name = L"cbx_ChipSize";
this->cbx_ChipSize->Size = System::Drawing::Size(77, 21);
this->cbx_ChipSize->TabIndex = 1;
this->cbx_ChipSize->ValueMember = L"Value";
//
any help pls ty!!!
Try something like this:
public ref class ComboboxItem
{
public:
ComboboxItem( String^ text, Object^ value )
{
_text = text;
_value = value;
}
. . . .
};
. . . .
cbx_ChipSize->Items->Add( gcnew ComboboxItem( "Chip Size", 0) );