Reputation: 757
I'm here again asking questions. I hope somebody would put some effort in answering this question.
So I have a datagrid view which had values from my database. I have a search button in my form which opens a new form and then there, there is a textbox which you can write the string that you want to search. The question is, How can do that to search and update my datagridview.
for ex. My datagrid view has the following values:
name: adam lewis, adam sandler, justin bieber, rebecca black
if i search only "adam" after I clicked ok and that 2nd form gets closed my datagrid view will update and will only show names which has adam on it.
name: adam lewis, adam sandler
**My Datagrid's values is bound by a datatable.
Just comment below if you don't understand the question and I will put pictures of my gui if that will help. THANK YOU VERY MUCH STACKOVERFLOW!!
it looks like this...
Here's a video example: http://www.youtube.com/watch?v=1OjZwBqVSVI
Upvotes: 2
Views: 3802
Reputation: 1346
What part of it do you need help though? The general idea is this, you want to be able to control your main form from your search form. You can do this:
In your main form you do 2 things implement UpdateDatatable and add an event handler on search button click:
private void Search_Click(object sender, EventArgs e)
{
SearchForm mySearchForm = new SearchForm();
mySearchForm.SetMainForm(this);
mySearchForm.Show();
}
public void UpdateDatatable(string searchWord)
{
//write your own code to update your datagridview by updating the datatable, filtering the datatable or creating a new datatable by using the parameter searchWord. I am saying datatable because I assume your datagridview is bound to a datatable.
}
In your search form:
public partial class SearchForm : Form
{
private Form mainForm;
public SearchForm()
{
InitializeComponent();
}
public void SetMainForm(Form fromMainForm)
{
mainForm = fromMainForm;
}
private void txtSearchWord_TextChanged(object sender, EventArgs e)
{
mainForm.UpdateDatatable(txtSearchWord.text);
}
}
Hope this helps
Upvotes: 3
Reputation: 558
Here is one way of doing this:
This is a crude way of doing things and not the optimal way, but it is a feasible one.
Hope this helps.
Upvotes: 0