Jump to content
  • Advertisement
Sign in to follow this  
PyroBlizzard

Managed C++ ComboBox Issues

This topic is 4852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, so here is the deal. I have in my program for it setup to get information from a specific directory, and fill in ComboBox A. Now comes up problem 1. When the information is put into ComboBox A, I would like for my program to automatically fill in the blank field with the first option, instead of just leaving it blank. From there, I want ComboBox A to run an event that effects ComboBox B. What I want to happen, is I want ComboBox B to read information from a subdirectory of the selected choice in ComboBox A. Now comes problem 2. The event is setup in the header file (as I just double clicked on the combobox for the event), and I cannot seem to get it to where I can use DirectoryInfo* in the header file. Questions being: 1. How can I make ComboBox A automatically highlight option 1? 2. How can I make ComboBox A's SelectedIndexChanged event either A. Allow usage of the DirectoryInfo code B. be put into the main .cpp file.

Share this post


Link to post
Share on other sites
Advertisement
PyroBlizzard

Its late, but I'll see if I can answer your questions.

1. You can make ComoboBoxA automatically highlight option 1 by calling the following when you read in the directory info:

comboBoxA->SelectedIndex = 0;

2. I'm not sure what you mean here. If you mean, "How do I populate box2 with the subdirectories located in the directory selected in ComboA," the answer is, create an event handler for "SelectedIndexChange" for ComboA, then whenever the event is called, just get the name of the directory from the selected index of boxA, then get the directories much as you did for ComboA the first time. Use the new list of subdirectories or files to populate ComboB. Here's a quick code example of that:


// Please note that its 12:26AM. This code is not as clean as it could be. =)
// But it should serve its purpose
Form1(void)
{
InitializeComponent();

DirectoryInfo* di = new DirectoryInfo(S"C:\\Workspace\\MyDir");
if( di->Exists )
{
String* dirs[] = Directory::GetDirectories( S"c:\\Workspace\\MyDir" );
Collections::IEnumerator* myEnum = dirs->GetEnumerator();
while( myEnum->MoveNext() )
{
comboBox1->Items->Add( myEnum->Current );
}
comboBox1->SelectedIndex = 0;
}
}

private: System::Void comboBox1_SelectedIndexChanged(System::Object * sender, System::EventArgs * e)
{
int index = comboBox1->SelectedIndex;
String* pString = comboBox1->Items->Item[index]->ToString();

comboBox2->Items->Clear();
comboBox2->Text = S"";

DirectoryInfo* di = new DirectoryInfo( pString );
if( di->Exists )
{
String* dirs[] = Directory::GetDirectories( pString );
Collections::IEnumerator* myEnum = dirs->GetEnumerator();
while( myEnum->MoveNext() )
{
comboBox2->Items->Add( myEnum->Current );
}
comboBox2->SelectedIndex = 0;
}
}


3. I wrote a quick mock-up Managed C++ application. I was able to use the DirectoryInfo class just fine in the .h file by adding the following "using" statement:

using namespace System::IO;

Share this post


Link to post
Share on other sites
System:IO is the only one I didnt put in the header file, and now I feel stupid, cause I remember that is right. Thank you so much for all your help.

Share this post


Link to post
Share on other sites
Ok, new problem. First, the code

private: System::Void cPlayerAccounts_SelectedIndexChanged(System::Object *  sender, System::EventArgs *  e)
{
System::String* directory = this->tWoWDir->get_Text();
System::String* dirName = String::Concat(directory, "\\WTF\\Account\\");
System::String* accountName = this->cPlayerAccounts->
DirectoryInfo* accountFolder = String::Concat(dirName, accountName);
if (accountFolder->Exists)
{
DirectoryInfo* playerName[] = accountFolder->GetDirectories();
for (int i = 0; i < playerName->Length; i++)
{
this->cPlayerCharacters->Items->Add(playerName);
}
}
}


Now, the issue is the System::String* accountName part. I dont know how to get the text of the currently selected item in ComboBox A (cPlayerAccounts). How would I go about doing this?

Share this post


Link to post
Share on other sites
PyroBlizzard,

If you check in the example code I provided you'll see the following:

int index = comboBox1->SelectedIndex;
String* pString = comboBox1->Items->Item[index]->ToString();

The first line gets the currently selected item from comboBox1, and then passes it into the array of items in order to get the string at that index.

For you that would be:

int index = cPlayerAccounts->SelectedIndex;
System::String* accountName = this->cPlayerAccounts->Items->Item[index]->ToString();

Again, good luck!

Share this post


Link to post
Share on other sites
Alright, Thank you so much for your help, JWalsh, and I have increased your rating cause of it.

New issue. Im running an open file dialog box, and I have it set that when the user clicks on ok, I need it to rerun a function that I have defined in my main cpp file. Only problem is that, once again, the event handlers are in the header file, and I cannot seem to figure out how I would run my function that is defined in my cpp file. Any ideas?

EDIT: Got it somewhat. I just copied over the function code into my event in the header file. Must be some better way though.

Anyways, new thing. I dont need an open file dialog box, I need an open directory dialog box. Any idea?

[Edited by - PyroBlizzard on June 8, 2005 7:31:29 PM]

Share this post


Link to post
Share on other sites
Ok, nevermind on that last one as well, as I figured it out. Just used a Regex to split it up into an array and used the first part of the array. Now I need to know how to send a post request to a server CGI script. Any ideas?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!