blazted 0 Newbie Poster

Never mind figured it out.

blazted 0 Newbie Poster

I created a text box event handler to only allow my textbox to accept Numbers only. The Event handler works great and does not allow anything but numbers except when the form first loads and the character entered is non-numeric it then allows the first charcter to be entered can be non-numberic. If I enter a number then erase it it will not allow a non-numeric character.

I saw one example of this but the texbox had a underline in it but it did not have any code in it.

Here is my event handler right now.

private void rtbQuantity_TextChanged(object sender, EventArgs e)
{
      rtbQuantity.KeyPress += new KeyPressEventHandler(rtbQuantity_KeyPress);
}

private void rtbQuantity_KeyPress(object sender, KeyPressEventArgs e)
{
    if ((e.KeyChar < '0') || (e.KeyChar > '9')) e.Handled = true;
}

Thank you

blazted 0 Newbie Poster

ok, in your GetProductsColor() you are populating the combo cmbProductColor - right? I would suggest doing cmbProductColor.Items.Clear(); before adding new stuff or you will append the values without getting rid of old values.

Later in the same function you are capturing selected item, well, the selected item is null because your user did not have a chance to actually seleect anything as of yet. This means that your strSelection is null. and when you call GetFirstImprintColors you are actually passing null to it, but it does not matter since you are not usign that string in the function anywho.

I would suggest following approach:

on load - populate both combo boxes, second combo visible = false;

go to the combo1_SelectedIndexChanged and specify that once the idex is changed, combo 1.visible = false and combo 2.visible is true;

go to the combo2_SelectedIndexChanged and do combo 2.visible = false; combo 1.visible = true.

Above events will ensure that once your user selects anything in the combo box 1, combo box 1 is now invisible and combo box 2 is visible. When user selects anything in combo box 2, combo 2 is invisible and combo 1 is visible

hope this helps

P.S. is this homework or something?

Thank You but I managed to solve it.

No it is not homework, I simply have never really worked with Forms before and I have never really done c# as well so this is very new to me. The more I work it the more …

blazted 0 Newbie Poster

Thank you the selected Index worked fine.

blazted 0 Newbie Poster

I have a combobox that is populated by a SQL querry. Problem is the first item of the comboBox where normally the comboBox.text go is blank. You have to drop down the menu item for the items to appear. I want to comboBox to populated with the first item in the first row. I am currently populating my comboBox with the add property

while (oleDbDataReader1.Read() == true)
{
    comboBox1.Items.add = oleDbDataReader1.GetString(0) ;   
}

This though is skipping the first field. How can I add the first result from the query to the first field in my comboBox?

Thanks

blazted 0 Newbie Poster

I have been trying to get this work and so far the only way i cna get this to work is if I use a If else statement that is dependent on the a user selection. But since I do not know the values of the combo box prior to the first entry I cannot assiga if else statement.

Is there any way to do a statment with a combo box on these osrt of lines?

if(combobox.selectedItem() = anything)
do this?

Since I do not know the argument prior to the selection I need the selected Item to be == to anything. Is there a way to do this?

Thanks

blazted 0 Newbie Poster

I have a Form that has 3 radio buttons grouped together. I have a default combobox selected on the form. When a user selects a item from the combo box a new combo box appears that is populated from the data in a access DB. Problem is that right now when you select a selection the new combo box does not appear. It instead appears when you select one of the other radio buttons then go back to the original ComboBox.

Here is the code.

First Part is the radio button which calls the next function

private void optProductColor_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (optProductColor.Checked == true)
                {              
                    this.lblProductColor.Visible = true;
                    this.cmbProductColor.Visible = true;
                    this.lblCustomerType.Visible = false;
                    this.cmbCustomerType.Visible = false;

                    GetProductColors();
                }
                    
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

        }

Here is the next function

private void GetProductColors()
        {
            try
            {   //DB calls to Stored Procedure
                //Read the DB into our ComboBox
                while (oleDbDataReader1.Read() == true)
                {
                    this.cmbProductColor.Items.Add(oleDbDataReader1.GetString(0));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                oleDbConnection1.Close();
            }

            //Get Selection from Combo Box
            string strSelection = cmbProductColor.SelectedItem.ToString();
            //Make next combobox visible
            this.cmbFirstColor.Visible = true;
                
            //Send String to First Imprint Color
            GetFirstImprintColors(strSelection);
        }

This calls the next function which is not displayed until I leave the radio button and then come back

private void GetFirstImprintColors(string strSelection)
        {
            try
            {
                //See if DB is open
                //DB calls
                //Read the DB into our ComboBox
                while (oleDbDataReader1.Read() == true)
                {
                    this.cmbFirstColor.Items.Add(oleDbDataReader1.GetString(0));          
                }
            }
            catch (Exception …
blazted 0 Newbie Poster

Thank you, this does help a lot. I thought it had some thing to do with passing the form class to my other classes. I still think in terms of console. I understand what you are saying but still am having problems. My temp solution was just turn my Output from my other classes into strings and then pass them to the form and write them directly from there. I did try what you said about passing the form but my classes still do not know about the rich text box. I tried to right click on the rick text box and go properties and change the modifier to public but my classes still do not know about it. I also tried using public class patient : application but it still did not know about my rich text box on the form.

This is how I have form now

namespace MedApp
{
        public partial class Application : Form
        {
            //Methods
            //Button Show Calls the Show All Method of the Meds
            //I want it to display this method in the rich text box
        }
        
        public structure provider
       {
           //Methods
       }

       public class patient
       {
           //Methods
       }

       public class meds : base patient
      {
             void ShowAll(Provider PI, others)
            {
                  //This method displays the complete listing
                 
            }
      }
}
blazted 0 Newbie Poster

This is the first time I have really done any GUI work. I had a console app in C++ that I rewrote into C# and am trying to make a GUI for it. However I am not sure how to display my classes show methods in the Text box. I can make it display text form within the form class. But I want it to be able to call the display method from my other classes and print out the output in a rich text box I have. I also want to clear the output if a user selects a different tab. I have not been able to find much info on printing from other classes.

What I have is one namespace with my forms class and several other classes in the namespace. I can write to the textbox from with the forms class but I am unable to write to the textbox from within my other classes.

Any help is appreciated.

Thanks

blazted 0 Newbie Poster

Thanks, i figured it was something with my bracing but could not get it to work.

Thanks

blazted 0 Newbie Poster

I have a binary tree and I am having problems with one function. It is my add function where I add another node to my tree. I use recursion to call it from within the function. I believe I am not using the correct syntax to call the node from within but I cannot understand why this is not working. I think I may be getting confused with how I am calling this.

Here is the function in question.

bool BinarySearchTree::addNode(METADATA **current_node, METADATA *new_node)
{
    if(*current_node == NULL)
    {
        *current_node = new_node;
        size++;
        return true;
    }
    else
    {
        if(strcmp(new_node->key, (*current_node)->key) < 0)
        {
            return addNode(&((current_node->left), new_node);
        }
        else if(strcmp(new_node->key, (*current_node)->key) > 0)
        {
            return addNode(&((*current_node->right), new_node);
        }
        else
        {
            delete new_node;
            return false;
        }
    }
}

Both of the recursion calls are getting the following errors

error C2227: left of '->left' must point to class/struct/union/generic type
error C2143: syntax error : missing ')' before ';'
Error 7 error C2660: 'BinarySearchTree::addNode' : function does not take 1 arguments

It seams like it does not like the left but this is defined in my structure

typedef struct METADATA
{
    struct METADATA(char *key, char *value)
    {
        strcpy(this->key, key);
        strcpy(this->value, value);
        left = NULL;
        right = NULL;
    }
    char key[SIZE_KEY];
    char value[SIZE_VALUE];
    struct METADATA* left;
    struct METADATA* right;
}METADATA;

Any help in understanding why my recursion call is not working is appreciated.

blazted 0 Newbie Poster

Well you did ask for char to double. I agree atoi sucks but he was asking for something simple. If you are trying to do a string to int or double do a simple search or post the code.


For Atof convert to c_str

blazted 0 Newbie Poster

Ahh thank you. I did that and it worked perfectly.

blazted 0 Newbie Poster

I wrote a hash table that takes a char as a key and for a test I am using a string for my value. It uses a linked list. But I am having a problem displaying the value. I have a function that displays the key correctly but the value is displayed as garbage. I am prety sure it is this one method that is causing it to display incorrectly but it complies and runs fine, i am just not sure why this does not work. Here is the method I think is not working and I am attaching the entire sample program as a txt file if someonecan take a look. I a little stuck on this.

bool Hashtable::get(char *key, string value)
{
    METADATA* temp = find(key);
    if(temp == NULL)
    {
        value = "";
        return false;
    }
    else
    {
        value = temp->value;
        return true;
    }
}

Here is my Display Function and it calls this function so I am assuming that for some reason the data is not bein copied correctly.

void displayAll(Hashtable *hashtable)
{
    char key[SIZE_KEY];
    char value[SIZE_VALUE];
    cout<< "\nCurrent nodes in hashtable: " << endl;
    hashtable->initIterator();
    while(hashtable->hasNext())
    {
        hashtable->getNextKey(key);
        hashtable->get(key, value);
        cout << "key: " << key << "\tvalue : " << value << endl;

    }
}

Thanks

blazted 0 Newbie Poster

You can use atoi to convert the char to a int or atof to a double

blazted 0 Newbie Poster

I am trying to define a structure for a hash table. I am making a constructor in my structure but I cannot get it to work with anything except chars. Strings always get me confused as how to manipulate them here. I have a string as my key and a custom Record class as my value. If I use chars as either one it works but does not work with my custom values.

typedef struct Metadata
{
    struct Metadata(string *key, Record* value)
    {
        this->key == key;
        this->value = value;
        next = NULL;
    }
    string key[SIZE_KEY];
    Record value[SIZE_VALUE];
    struct Metadata * next;
}Metadata;

Can anyone point me in the correct direction?

Thanks

blazted 0 Newbie Poster

I have trying to parse string data in a stack into a arithmetic equivalent. I implemented a stack and used strtok to parse it into tokens and placed them into my stack. Now I am trying to pull them off the stack and do the expression that is carrying them. But I am lost on how to do this. On my Stack I will have ( 2 + 2) + 3 and I can pop them off at a time to get to keep the correct order but I have no idea how to make them into an equation from the stack. Can any body point me to a way to do this? I am not looking for code but some type of explanation on how to create this. I can pull them off the stack and know how to convert the doubles into doubles but how can i assign this into a string for the program to do the math?

Thanks