FindStringExtract() won't work if ComboBox populated by setting DataSource

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

    FindStringExtract() won't work if ComboBox populated by setting DataSource

    I notice in the ComboBox, when set its DataSource, its .Items will be empty
    collection. And .FindStringExtr act() will not find anything. Seems this is
    not documented.


    Ryan


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: FindStringExtra ct() won't work if ComboBox populated by setting DataSource

    Ryan,

    FindStringExact (and FindString) will only work when you populate the
    list through the Items property. It doesn't work for databinding.

    However, you can create a general search algorithm that takes the list
    source, as well as the display item, and evalulates each item in the list,
    looking for the string.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Ryan Liu" <ad50275324@onl ine.sh.cn> wrote in message
    news:u2yY$WKiGH A.2268@TK2MSFTN GP04.phx.gbl...[color=blue]
    >I notice in the ComboBox, when set its DataSource, its .Items will be empty
    > collection. And .FindStringExtr act() will not find anything. Seems this is
    > not documented.
    >
    >
    > Ryan
    >
    >[/color]


    Comment

    • Ryan Liu

      #3
      Re: FindStringExtra ct() won't work if ComboBox populated by setting DataSource

      Thanks, Nicholas !

      Now I write so it will fist go though its DataSource(cast to IList), if not
      found, then I try FindStringExact (). I was trying to write a generic code,
      now I hope this is also safe enough.

      Regards,
      Ryan


      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> дÈëÓʼþ
      news:%23avo7iLi GHA.1208@TK2MSF TNGP02.phx.gbl. ..[color=blue]
      > Ryan,
      >
      > FindStringExact (and FindString) will only work when you populate the
      > list through the Items property. It doesn't work for databinding.
      >
      > However, you can create a general search algorithm that takes the list
      > source, as well as the display item, and evalulates each item in the list,
      > looking for the string.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Ryan Liu" <ad50275324@onl ine.sh.cn> wrote in message
      > news:u2yY$WKiGH A.2268@TK2MSFTN GP04.phx.gbl...[color=green]
      > >I notice in the ComboBox, when set its DataSource, its .Items will be[/color][/color]
      empty[color=blue][color=green]
      > > collection. And .FindStringExtr act() will not find anything. Seems this[/color][/color]
      is[color=blue][color=green]
      > > not documented.
      > >
      > >
      > > Ryan
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: FindStringExtra ct() won't work if ComboBox populated by setting DataSource

        Ryan,

        Well, I would switch on whether or not there is a data source or not,
        but yes, using the IList implementation, along with the DataMember and the
        DisplayMember properties should be enough.


        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "Ryan Liu" <ad50275324@onl ine.sh.cn> wrote in message
        news:epcjsnMiGH A.1612@TK2MSFTN GP04.phx.gbl...[color=blue]
        > Thanks, Nicholas !
        >
        > Now I write so it will fist go though its DataSource(cast to IList), if
        > not
        > found, then I try FindStringExact (). I was trying to write a generic code,
        > now I hope this is also safe enough.
        >
        > Regards,
        > Ryan
        >
        >
        > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om>
        > дÈëÓʼþ
        > news:%23avo7iLi GHA.1208@TK2MSF TNGP02.phx.gbl. ..[color=green]
        >> Ryan,
        >>
        >> FindStringExact (and FindString) will only work when you populate the
        >> list through the Items property. It doesn't work for databinding.
        >>
        >> However, you can create a general search algorithm that takes the
        >> list
        >> source, as well as the display item, and evalulates each item in the
        >> list,
        >> looking for the string.
        >>
        >> Hope this helps.
        >>
        >>
        >> --
        >> - Nicholas Paldino [.NET/C# MVP]
        >> - mvp@spam.guard. caspershouse.co m
        >>
        >> "Ryan Liu" <ad50275324@onl ine.sh.cn> wrote in message
        >> news:u2yY$WKiGH A.2268@TK2MSFTN GP04.phx.gbl...[color=darkred]
        >> >I notice in the ComboBox, when set its DataSource, its .Items will be[/color][/color]
        > empty[color=green][color=darkred]
        >> > collection. And .FindStringExtr act() will not find anything. Seems this[/color][/color]
        > is[color=green][color=darkred]
        >> > not documented.
        >> >
        >> >
        >> > Ryan
        >> >
        >> >[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        Working...