-1

Using combobox at C#, VS 2010, Forms.

After you drop a combobox, you scroll on list of choices with your mouse. Which event triggers this on MSDN Combobox Events

example: list of choices on combobox are apple, banana, chocolate, etc., you point at apple it calls the event, you point on banana it calls the same event, etc.

Also how do I get the values its pointing at?

If there is no event available, can I make one via program?

Been googling for a long time now can't seem to find what I need.

Ace Caserya
  • 2,825
  • 3
  • 25
  • 35
  • What event are you actually using? You should be able to get something from the argument, or at least `combobox.SelectedItem`. – gunr2171 Oct 28 '13 at 02:56
  • I've tried SelectedIndexChange, SelectedValueChanged, SelectionChangeCommitted,ValueMemberChanged. None of which works. – Ace Caserya Oct 28 '13 at 02:58
  • You got more than one because I upvoted you - I have no idea why, I think some people are a little trigger happy. – Jim W Oct 28 '13 at 03:11
  • You are currently at +2/-3. The downvote text reads `This question does not show any research effort; it is unclear or not useful`. Your question is mildly unclear, and you don't **show** any research effort. – gunr2171 Oct 28 '13 at 03:13
  • I see I tried hard explaining it, I even gave an example. I did miss the highlighted part. As per research I did my best researching on event, just so happen there was none. Instead it's clear hard coding part. – Ace Caserya Oct 28 '13 at 03:15

2 Answers2

2
  1. Which event triggers on this... If you create a combo box and add items, you can set the SelectedIndexChanged event and set it to your own custom event handler, like this:

    comboBox1.Items.Add("Apple");
    comboBox1.Items.Add("Banana");
    comboBox1.Items.Add("chocolate");
    
    comboBox1.SelectedIndexChanged += ComboBox1OnSelectedIndexChanged;
    
  2. The method receives a sender object that is of type combobox, the only tricky thing is that the signature sets it to an object. Casting it allows us to pull out the value.

    private void ComboBox1OnSelectedIndexChanged(object sender, EventArgs eventArgs)
    {
        myvalue = ((ComboBox)sender).SelectedValue;
    }
    
crthompson
  • 15,653
  • 6
  • 58
  • 80
  • It does not work unless I choose an Item, what i need is a trigger during selection... before it is chosen. Like while scrolling down the list of dropped down items. – Ace Caserya Oct 28 '13 at 03:06
  • 1
    @HenryHughes, (to your deleted comment), it may not be possible/easy to have an event fire when you change the highlight of an item in a combo box, [see this for an example](http://social.msdn.microsoft.com/Forums/windows/en-US/e234c4a7-0cf7-4284-a072-8152f7593002/combobox-item-highlight-event?forum=winforms). – gunr2171 Oct 28 '13 at 03:06
  • that's the one I'm looking for. Thanks. – Ace Caserya Oct 28 '13 at 03:08
0

Seems like you could get what you want from this

Redrawing of owner-drawn winforms combobox items

specifically when

(state & DrawItemState.HotLight) > 0

Let me know if more explanation is in order.

EDIT --

What I mean is, by implementing ownerdraw, you are made aware of what item the mouse is over. When the mouse is over the item, then, per the linked article

((state & DrawItemState.Selected) > 0) || ((state & DrawItemState.HotLight) > 0)

is true.

So in that case you can fire an event as needed with the info the OP wants.

Community
  • 1
  • 1
Jim W
  • 4,866
  • 1
  • 27
  • 43