Hello,

In order to introduce myself to C# and, in particular, Visual C# I decided to make a small program with 'windows forms'. At the moment I have some questions:

1) Im using a grid (dataGridView). I'd like a menuStrip (I dont know if is exacly that component) to appear when the mouse's right button is clicked. For each row of grid, when I click on the mouse's right button, a menu with options appears. How can I do that?

2) Something is typed in a textBox. I would like to, after that, ENTER key is 'activated' so I don't have to click on a button, I just press on ENTER key. How can I do that?

3) Last question. Im coding in win Vista where I changed the appearance of dataGridView (row's selection color, etc). However when I tried to run the application on winXP that changes make no effect. Is there a way I could, knowing witch OS is running (XP or Vista), apply a "xp style" or "vista style"?


Thanks in advance for your time. Every sugestion will be very appreciated.
(and sorry for my poor english :))

1) Use the control 'ContextMenuStrip'. You can Easily add items to this controls. Once done, use the Right click event of the dataGridView control you have in your application, and display this contextMenuStrip at the current location of the mouse.

2)Use the KeyPress event handler for the textbox and type in the following:

if (e.KeyChar == '\r')
btnSubmit.PerformClick();

where btnSubmit can be replaced by the name of your button.

3)When changing colors, if you want the colors to be exactly the same if you change the theme of windows or version, use Web or Custom Colors and not the System Colors.

Hope this helps.

Hello,

In order to introduce myself to C# and, in particular, Visual C# I decided to make a small program with 'windows forms'. At the moment I have some questions:

1) Im using a grid (dataGridView). I'd like a menuStrip (I dont know if is exacly that component) to appear when the mouse's right button is clicked. For each row of grid, when I click on the mouse's right button, a menu with options appears. How can I do that?

2) Something is typed in a textBox. I would like to, after that, ENTER key is 'activated' so I don't have to click on a button, I just press on ENTER key. How can I do that?

3) Last question. Im coding in win Vista where I changed the appearance of dataGridView (row's selection color, etc). However when I tried to run the application on winXP that changes make no effect. Is there a way I could, knowing witch OS is running (XP or Vista), apply a "xp style" or "vista style"?


Thanks in advance for your time. Every sugestion will be very appreciated.
(and sorry for my poor english :))

No Worries!
Please mark the thread as solved if you think you've solved the problems you were facing!

Well, I got another question.

Im trying to use KeyPress event handler with text box but I got this error:

No overload for 'search_textbox_KeyPress' matches delegate 'System.EventHandler'

I dont understand why.

Here it is the code I have:

    this.search_textbox.KeyPress += new System.EventHandler(this.search_textbox_KeyPress);
    private void search_textbox_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == '\r')
            go_button.PerformClick();
    }

If I change "KeyPressEventArgs" by "Eventargs" the error is:

Cannot implicitly convert type 'System.EventHandler' to 'System.Windows.Forms.KeyPressEventHandler'

What is missing?

Thanks!

Edited 3 Years Ago by mike_2000_17: Fixed formatting

lol thats good!!

I've heard this story, not sure if its true.. Theres a helpdesk in the CS department in some university in US, that you can goto if you have any problems in Computer Science subjects. They decided to keep a small teddy bear on the side of the desk. Before you can come and discuss the issue you are facing with one of the person on this desk, you first have to explain it to this Teddy, you have to speak out loud, not just in your head.. and you have to be explain it well what you are trying to do, just as you would do to a person.

The Result?? A vast majority of students got their problems solved by the Teddy itself! Did'nt have to speak to the helpdesk person!

Its actually true, if you try to explain it to someone, it is quite possible that you will find the answer or the error!

I think every programmer should have a teddy on their desk!

ahah thats true!
It happens a lot of times. Just when we talk to someone (well, or something) or we try to express our idea we get the answer, we answer ourselves.

Thanks Jatin!

This question has already been answered. Start a new discussion instead.