Replace a character in combo box

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kay

    Replace a character in combo box

    Hi All,

    I'm trying to write a small sub/function to replace some (invalid) character
    in a combo box, or may be even text box. For example, I have several combo
    boxes that allows user to select a time value, i.e. 21:30, however I also
    want to allow them to enter a time, as a result I want to replace comma,
    fullstop etc with a colon ":". I've done this in VB6 keypress event,
    however with the "sender", "e" in .net I'm a bit lost... I don't have much
    experience in .net could you guys give me some help?

    Thanks!

    Kay



  • Cor Ligthert [MVP]

    #2
    Re: Replace a character in combo box

    Kay,

    Here is an autocomplete sample for a combobox, in my idea are all the
    ingredients in that to make what you want. (It begins with building a
    sample).



    I hope this helps,

    Cor

    "Kay" <kk@kk.com.kksc hreef in bericht
    news:%23OH%23Iq ZxGHA.1284@TK2M SFTNGP05.phx.gb l...
    Hi All,
    >
    I'm trying to write a small sub/function to replace some (invalid)
    character
    in a combo box, or may be even text box. For example, I have several
    combo
    boxes that allows user to select a time value, i.e. 21:30, however I also
    want to allow them to enter a time, as a result I want to replace comma,
    fullstop etc with a colon ":". I've done this in VB6 keypress event,
    however with the "sender", "e" in .net I'm a bit lost... I don't have much
    experience in .net could you guys give me some help?
    >
    Thanks!
    >
    Kay
    >
    >
    >

    Comment

    • Kay

      #3
      Re: Replace a character in combo box

      Hi Cor & all,

      Core thanks for your response, I have a look on your web site, but I think
      it may be a bit difficult if I want to use it for a text box - after I think
      again what I really want - if it's possible I want to create a function,
      with a papramater, then check whether it's a valid character, i.e. in this
      case ":" & number are valid, if not cancel the character entered, or replace
      with other character....um ... that sounds good to me but if you guys have a
      better advice please tell me!! So now the problem I have is how to capture
      the character just entered....

      Kay

      "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
      news:OxaogjaxGH A.5064@TK2MSFTN GP04.phx.gbl...
      Kay,
      >
      Here is an autocomplete sample for a combobox, in my idea are all the
      ingredients in that to make what you want. (It begins with building a
      sample).
      >

      >
      I hope this helps,
      >
      Cor
      >
      "Kay" <kk@kk.com.kksc hreef in bericht
      news:%23OH%23Iq ZxGHA.1284@TK2M SFTNGP05.phx.gb l...
      >Hi All,
      >>
      >I'm trying to write a small sub/function to replace some (invalid)
      >character
      >in a combo box, or may be even text box. For example, I have several
      >combo
      >boxes that allows user to select a time value, i.e. 21:30, however I also
      >want to allow them to enter a time, as a result I want to replace comma,
      >fullstop etc with a colon ":". I've done this in VB6 keypress event,
      >however with the "sender", "e" in .net I'm a bit lost... I don't have
      >much
      >experience in .net could you guys give me some help?
      >>
      >Thanks!
      >>
      >Kay
      >>
      >>
      >>
      >
      >

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Replace a character in combo box

        Kay,

        Have a look at the thenthousand samples about a numeric textbox on Internet
        by using Google.

        I have not set this one on our site, because there is nothing in it for
        pushing the del key etc.
        Especially for your question, use the keyup event most people want to use
        the key down, which gives less information in the KeyEventArgs.

        \\\\
        Private Sub Form1_Load(ByVa l sender As System.Object, _
        ByVal e As System.EventArg s) Handles MyBase.Load
        Me.TextBox1.Max Length = 10
        End Sub
        Private Sub textbox1_KeyUp( ByVal sender As Object, _
        ByVal e As System.Windows. Forms.KeyEventA rgs) Handles textbox1.KeyUp
        If e.KeyValue <8 Then
        If Not IsNumeric(TextB ox1.Text) Then
        If TextBox1.Text.L ength 0 Then
        MessageBox.Show ("Only numeric is allowed")

        TextBox1.Select ionStart = TextBox1.Text.L ength - 1
        TextBox1.Select ionLength = 1
        End If

        End If
        End If
        End Sub
        ///

        I hope this helps,

        Cor





        "Kay" <kk@kk.com.kksc hreef in bericht
        news:OhDRUKbxGH A.4416@TK2MSFTN GP03.phx.gbl...
        Hi Cor & all,
        >
        Core thanks for your response, I have a look on your web site, but I think
        it may be a bit difficult if I want to use it for a text box - after I
        think again what I really want - if it's possible I want to create a
        function, with a papramater, then check whether it's a valid character,
        i.e. in this case ":" & number are valid, if not cancel the character
        entered, or replace with other character....um ... that sounds good to me
        but if you guys have a better advice please tell me!! So now the problem
        I have is how to capture the character just entered....
        >
        Kay
        >
        "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
        news:OxaogjaxGH A.5064@TK2MSFTN GP04.phx.gbl...
        >Kay,
        >>
        >Here is an autocomplete sample for a combobox, in my idea are all the
        >ingredients in that to make what you want. (It begins with building a
        >sample).
        >>
        >http://www.vb-tips.com/dbPages.aspx?...f-c22411591992
        >>
        >I hope this helps,
        >>
        >Cor
        >>
        >"Kay" <kk@kk.com.kksc hreef in bericht
        >news:%23OH%23I qZxGHA.1284@TK2 MSFTNGP05.phx.g bl...
        >>Hi All,
        >>>
        >>I'm trying to write a small sub/function to replace some (invalid)
        >>character
        >>in a combo box, or may be even text box. For example, I have several
        >>combo
        >>boxes that allows user to select a time value, i.e. 21:30, however I
        >>also
        >>want to allow them to enter a time, as a result I want to replace comma,
        >>fullstop etc with a colon ":". I've done this in VB6 keypress event,
        >>however with the "sender", "e" in .net I'm a bit lost... I don't have
        >>much
        >>experience in .net could you guys give me some help?
        >>>
        >>Thanks!
        >>>
        >>Kay
        >>>
        >>>
        >>>
        >>
        >>
        >
        >

        Comment

        • Kay

          #5
          Re: Replace a character in combo box

          Hi Cor,

          Thanks for your help! Can I ask one more question? :P

          Is there something like an ASCII table that represent a KeyValue? Coz I
          want to capture more characters other than numbers. Tried to search through
          the help but it didn't tell much.... may be I'm looking at the wrong
          direction...

          Kay


          "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
          news:u7No3NbxGH A.4444@TK2MSFTN GP02.phx.gbl...
          Kay,
          >
          Have a look at the thenthousand samples about a numeric textbox on
          Internet by using Google.
          >
          I have not set this one on our site, because there is nothing in it for
          pushing the del key etc.
          Especially for your question, use the keyup event most people want to use
          the key down, which gives less information in the KeyEventArgs.
          >
          \\\\
          Private Sub Form1_Load(ByVa l sender As System.Object, _
          ByVal e As System.EventArg s) Handles MyBase.Load
          Me.TextBox1.Max Length = 10
          End Sub
          Private Sub textbox1_KeyUp( ByVal sender As Object, _
          ByVal e As System.Windows. Forms.KeyEventA rgs) Handles textbox1.KeyUp
          If e.KeyValue <8 Then
          If Not IsNumeric(TextB ox1.Text) Then
          If TextBox1.Text.L ength 0 Then
          MessageBox.Show ("Only numeric is allowed")
          >
          TextBox1.Select ionStart = TextBox1.Text.L ength - 1
          TextBox1.Select ionLength = 1
          End If
          >
          End If
          End If
          End Sub
          ///
          >
          I hope this helps,
          >
          Cor
          >
          >
          >
          >
          >
          "Kay" <kk@kk.com.kksc hreef in bericht
          news:OhDRUKbxGH A.4416@TK2MSFTN GP03.phx.gbl...
          >Hi Cor & all,
          >>
          >Core thanks for your response, I have a look on your web site, but I
          >think it may be a bit difficult if I want to use it for a text box -
          >after I think again what I really want - if it's possible I want to
          >create a function, with a papramater, then check whether it's a valid
          >character, i.e. in this case ":" & number are valid, if not cancel the
          >character entered, or replace with other character....um ... that sounds
          >good to me but if you guys have a better advice please tell me!! So now
          >the problem I have is how to capture the character just entered....
          >>
          >Kay
          >>
          >"Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
          >news:OxaogjaxG HA.5064@TK2MSFT NGP04.phx.gbl.. .
          >>Kay,
          >>>
          >>Here is an autocomplete sample for a combobox, in my idea are all the
          >>ingredients in that to make what you want. (It begins with building a
          >>sample).
          >>>
          >>http://www.vb-tips.com/dbPages.aspx?...f-c22411591992
          >>>
          >>I hope this helps,
          >>>
          >>Cor
          >>>
          >>"Kay" <kk@kk.com.kksc hreef in bericht
          >>news:%23OH%23 IqZxGHA.1284@TK 2MSFTNGP05.phx. gbl...
          >>>Hi All,
          >>>>
          >>>I'm trying to write a small sub/function to replace some (invalid)
          >>>character
          >>>in a combo box, or may be even text box. For example, I have several
          >>>combo
          >>>boxes that allows user to select a time value, i.e. 21:30, however I
          >>>also
          >>>want to allow them to enter a time, as a result I want to replace
          >>>comma,
          >>>fullstop etc with a colon ":". I've done this in VB6 keypress event,
          >>>however with the "sender", "e" in .net I'm a bit lost... I don't have
          >>>much
          >>>experience in .net could you guys give me some help?
          >>>>
          >>>Thanks!
          >>>>
          >>>Kay
          >>>>
          >>>>
          >>>>
          >>>
          >>>
          >>
          >>
          >
          >

          Comment

          • Cor Ligthert [MVP]

            #6
            Re: Replace a character in combo box

            Kay,

            No I thought you know that, you see in the latest sample the 8 but there are
            more therefore I said it was not complete.

            Therefore I said have a look for a numeric textbox

            This is a nice solution with the control characters


            I took from Internet the first table I could find. I know that there is a
            nicer one on MSDN, but with the same search information I could not find it
            there, maybe you can try that yourself.



            I hope this helps,

            Cor

            "Kay" <kk@kk.com.kksc hreef in bericht
            news:uADeVnmxGH A.4660@TK2MSFTN GP02.phx.gbl...
            Hi Cor,
            >
            Thanks for your help! Can I ask one more question? :P
            >
            Is there something like an ASCII table that represent a KeyValue? Coz I
            want to capture more characters other than numbers. Tried to search
            through the help but it didn't tell much.... may be I'm looking at the
            wrong direction...
            >
            Kay
            >
            >
            "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
            news:u7No3NbxGH A.4444@TK2MSFTN GP02.phx.gbl...
            >Kay,
            >>
            >Have a look at the thenthousand samples about a numeric textbox on
            >Internet by using Google.
            >>
            >I have not set this one on our site, because there is nothing in it for
            >pushing the del key etc.
            >Especially for your question, use the keyup event most people want to use
            >the key down, which gives less information in the KeyEventArgs.
            >>
            >\\\\
            >Private Sub Form1_Load(ByVa l sender As System.Object, _
            > ByVal e As System.EventArg s) Handles MyBase.Load
            > Me.TextBox1.Max Length = 10
            > End Sub
            > Private Sub textbox1_KeyUp( ByVal sender As Object, _
            > ByVal e As System.Windows. Forms.KeyEventA rgs) Handles textbox1.KeyUp
            > If e.KeyValue <8 Then
            > If Not IsNumeric(TextB ox1.Text) Then
            > If TextBox1.Text.L ength 0 Then
            > MessageBox.Show ("Only numeric is allowed")
            >>
            > TextBox1.Select ionStart = TextBox1.Text.L ength - 1
            > TextBox1.Select ionLength = 1
            > End If
            >>
            > End If
            > End If
            > End Sub
            >///
            >>
            >I hope this helps,
            >>
            >Cor
            >>
            >>
            >>
            >>
            >>
            >"Kay" <kk@kk.com.kksc hreef in bericht
            >news:OhDRUKbxG HA.4416@TK2MSFT NGP03.phx.gbl.. .
            >>Hi Cor & all,
            >>>
            >>Core thanks for your response, I have a look on your web site, but I
            >>think it may be a bit difficult if I want to use it for a text box -
            >>after I think again what I really want - if it's possible I want to
            >>create a function, with a papramater, then check whether it's a valid
            >>character, i.e. in this case ":" & number are valid, if not cancel the
            >>character entered, or replace with other character....um ... that sounds
            >>good to me but if you guys have a better advice please tell me!! So now
            >>the problem I have is how to capture the character just entered....
            >>>
            >>Kay
            >>>
            >>"Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
            >>news:Oxaogjax GHA.5064@TK2MSF TNGP04.phx.gbl. ..
            >>>Kay,
            >>>>
            >>>Here is an autocomplete sample for a combobox, in my idea are all the
            >>>ingredient s in that to make what you want. (It begins with building a
            >>>sample).
            >>>>
            >>>http://www.vb-tips.com/dbPages.aspx?...f-c22411591992
            >>>>
            >>>I hope this helps,
            >>>>
            >>>Cor
            >>>>
            >>>"Kay" <kk@kk.com.kksc hreef in bericht
            >>>news:%23OH%2 3IqZxGHA.1284@T K2MSFTNGP05.phx .gbl...
            >>>>Hi All,
            >>>>>
            >>>>I'm trying to write a small sub/function to replace some (invalid)
            >>>>character
            >>>>in a combo box, or may be even text box. For example, I have several
            >>>>combo
            >>>>boxes that allows user to select a time value, i.e. 21:30, however I
            >>>>also
            >>>>want to allow them to enter a time, as a result I want to replace
            >>>>comma,
            >>>>fullstop etc with a colon ":". I've done this in VB6 keypress event,
            >>>>however with the "sender", "e" in .net I'm a bit lost... I don't have
            >>>>much
            >>>>experienc e in .net could you guys give me some help?
            >>>>>
            >>>>Thanks!
            >>>>>
            >>>>Kay
            >>>>>
            >>>>>
            >>>>>
            >>>>
            >>>>
            >>>
            >>>
            >>
            >>
            >
            >

            Comment

            Working...