Skip to content

Instantly share code, notes, and snippets.

@gideondsouza
Created December 2, 2011 11:53
Show Gist options
  • Save gideondsouza/1422982 to your computer and use it in GitHub Desktop.
Save gideondsouza/1422982 to your computer and use it in GitHub Desktop.
Simple Rx Instance Search
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SearchList("");//load all
ControlScheduler cs = new ControlScheduler(this);//WE NEED THIS.
Observable.FromEventPattern(h => textBox1.TextChanged += h,
h => textBox1.TextChanged -= h)
//^tell Rx about our event
.Throttle(TimeSpan.FromMilliseconds(500), cs)///throttle
.Do(a => SearchList(textBox1.Text))//do this method
.Subscribe();//this is where we tell it to begin all the magic
}
string[] list = new string[] { "gideon", "gabby", "joan", "jessica", "bob", "bill", "sam", "johann" };
void SearchList(string query)
{
listBox1.Items.Clear();
foreach (var item in list.Where(s => s.Contains(query)))
{
listBox1.Items.Add(item);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment