Created
December 2, 2011 11:53
-
-
Save gideondsouza/1422982 to your computer and use it in GitHub Desktop.
Simple Rx Instance Search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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