I'm C# and would like to get a sanity check from the group to ensure
that I'm going down the right road.
The first form in my mini-application is a search screen. I have an
image of it here: www.netopia.ca/c_sharp/search.png . There is a
datagrid that uses a dataview as the data source. On a keyup event for
the textbox, I set the rowfilter property of the dataview. Here's the
code for the event:
private void txtSearch_KeyUp (object sender, KeyEventArgs e)
{
string strRowFilter;
if (txtSearch.Text .Length == 0)
{
// If no text is present, use no filter.
strRowFilter = "";
}
else
{
// Column 1 of the table is used for searching
strRowFilter =
_dvSearchResult s.Table.Columns[1].ColumnName + " LIKE '%" +
txtSearch.Text + "%'";
}
// Specify the row filter
_dvSearchResult s.RowFilter = strRowFilter;
}
That I think is fine. What I'm not sure that I did correctly is
related to the combobox. The combobox essentially dictates which table
the dataview is using to filter. I use the SelectedValueCh anged event
on the combobox to update a searchtype string:
private void cboSearchType_S electedValueCha nged(object sender,
EventArgs e)
{
// Set the search type
_strSeachType = cboSearchType.T ext;
}
The set accessor for the _strSeachType property is:
set
{
// Assign the Table of the DataView to the appropriate
table
if (value.Equals(" Domains"))
{
_dvSearchResult s.Table =
domainsDataSet. tbl_domains;
}
else if (value.Equals(" Customers"))
{
_dvSearchResult s.Table =
domainsDataSet. tbl_customers;
}
else if (value.Equals(" Registrars"))
{
_dvSearchResult s.Table =
domainsDataSet. tbl_registrars;
}
else
{
MessageBox.Show ("Invalid Entry for Search Type");
}
// Reset the row filter
_dvSearchResult s.RowFilter = "";
// Add a table style to the data grid. This allows us
to
// set the width of a column
DataGridTableSt yle dgts = new DataGridTableSt yle();
dgts.MappingNam e = _dvSearchResult s.Table.TableNa me;
// Clear the current table style and set the new one
dgSearchResults .TableStyles.Cl ear();
dgSearchResults .TableStyles.Ad d(dgts);
// Set the visible column
datagrid_SetVis ibleColumn(dgts , 1);
// Refresh the DataGrid
dgSearchResults .Refresh();
}
I'm wondering if I did this correctly or not. Ultimately it works but
I'm wondering what the better ways are.
I have questions about my dgSearchResults _MouseDown() method, but I
think I'll same that for another post.
The full code for this form is at http://www.netopia.ca/c_sharp/SearchForm.cs
..
thanks,
Aaron