csharp combo automatic drop down listing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shibili
    New Member
    • Jul 2010
    • 4

    csharp combo automatic drop down listing

    i am basically a vb6 programmer new in csharp. i want to know how to get drop down list in combobox, when keydown arrow pressed. Now it came when alt+keydown pressed. i am already tried to pass sendkeys alt+keydown through code, when keydown pressed.but no effect , pls help


    Regards
    shibi
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Sorry, I'm not quite understanding. Do you need the dropdown to expand when you press the down arrow, or alt plus the down arrow, or both?

    Please clarify, thanks!

    *Edit: In looking at this further, it seems alt+down already expands a combobox in .NET.

    Comment

    • shibili
      New Member
      • Jul 2010
      • 4

      #3
      Originally posted by GaryTexmo
      Sorry, I'm not quite understanding. Do you need the dropdown to expand when you press the down arrow, or alt plus the down arrow, or both?

      Please clarify, thanks!

      *Edit: In looking at this further, it seems alt+down already expands a combobox in .NET.
      i want to expand drop down to press down arrow

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        Ah ok, that's easy enough.

        (The combo box, by default, does expand on alt+down arrow by the way)

        Anyway, you can accomplish this by creating an event handler to handle the KeyDown event of a combo box. In that method, you can see if the key code is Keys.Down (may want to make sure the modifiers don't include alt, or it interferes with alt+down) and set the DroppedDown property of a combo box to true.

        Comment

        • shibili
          New Member
          • Jul 2010
          • 4

          #5
          Originally posted by GaryTexmo
          Ah ok, that's easy enough.

          (The combo box, by default, does expand on alt+down arrow by the way)

          Anyway, you can accomplish this by creating an event handler to handle the KeyDown event of a combo box. In that method, you can see if the key code is Keys.Down (may want to make sure the modifiers don't include alt, or it interferes with alt+down) and set the DroppedDown property of a combo box to true.
          thanks gary, u help me a lot.

          pls help me on my datagrid question

          i wrote the below code and it works fine.


          in initialize componeent add
          this.cmbAcGroup .KeyPress += new System.Windows. Forms.KeyPressE ventHandler(thi s.cmbAcGroup_Ke yPress);
          -------------
          here cmbAcgroup is a combobox

          private void cmbAcGroup_KeyP ress(object sender, System.Windows. Forms.KeyPressE ventArgs e)
          {
          this.AutoComple te(this.cmbAcGr oup, e, true);
          cmbAcGroup.Focu s();
          cmbAcGroup.Drop pedDown = true;
          if (e.KeyChar == (char)13 )
          {
          cmbAcGroup.Drop pedDown = false;
          }
          }


          #region Auto Complete combo box
          public void AutoComplete(Co mboBox cb, System.Windows. Forms.KeyPressE ventArgs e, bool blnLimitToList)
          {
          string strFindStr = "";

          if (e.KeyChar == (char)8)
          {
          if (cb.SelectionSt art <= 1)
          {
          cb.Text = "";
          return;
          }

          if (cb.SelectionLe ngth == 0)
          strFindStr = cb.Text.Substri ng(0, cb.Text.Length - 1);
          else
          strFindStr = cb.Text.Substri ng(0, cb.SelectionSta rt - 1);
          }
          else
          {
          if (cb.SelectionLe ngth == 0)
          strFindStr = cb.Text + e.KeyChar;
          else
          strFindStr = cb.Text.Substri ng(0, cb.SelectionSta rt) + e.KeyChar;
          }

          int intIdx = -1;

          // Search the string in the ComboBox list.

          intIdx = cb.FindString(s trFindStr);

          if (intIdx != -1)
          {
          cb.SelectedText = "";
          cb.SelectedInde x = intIdx;
          cb.SelectionSta rt = strFindStr.Leng th;
          cb.SelectionLen gth = cb.Text.Length;
          e.Handled = true;
          }
          else
          {
          e.Handled = blnLimitToList;
          }

          }

          #endregion

          Comment

          • GaryTexmo
            Recognized Expert Top Contributor
            • Jul 2009
            • 1501

            #6
            Please keep your questions confined to the topic. If you have a datagrid question, please post another topic or if you already have one, please wait for an answer there.

            Also, it really helps to wrap your code in code tags. It's the little # button on your editing box.

            Lastly, I'm not overly experienced with data grids, so I tend to let the other experts answer those ones.

            Comment

            Working...