search - Searching in datagridview using c# -
After loading a table in the DataGrade view, I am generating items from a Cambodia with the Data Grid column header. From the Combobox I am selecting the column and I have a textbox for the search value given by the user. I am using the following code:
string searchfortext = txtCrudSearch.Text; DgvLoadTable.ClearSelection (); DgvLoadTable.SelectionMode = DataGridViewSelectionMode.FullRowSelect; Try {Foreach (DatagridViewRow line in dgvLoadTable.Rows) {if (row.Cells [cboCrudSearchColumn.SelectedIndex] .Value.ToString (). Equals (SearchForText)) {row.Selected = true; // If I use the break here, the code does not give an exception / but only highlighting one line I want to return all the rows, which matches the // with the search string}}} Catch (Exceptional) {message box. Show (ex.Message); } Now, the problems are:
- Exception to me is not set for an example of "object reference object" / li>
- How can I return to the datagrid instead of just lighting?
- Search is case sensitive, how does it work for all types?
I know this. If someone needs a solution, then the code is as follows:
Private Zero btnCrudSearch_Click (Object Sender, EventArgs e) {dgvLoadTable.CurrentCell = null; DgvLoadTable.AllowUserToAddRows = Incorrect; DgvLoadTable.ClearSelection (); DgvLoadTable.SelectionMode = DataGridViewSelectionMode.FullRowSelect; DgvLoadTable.ReadOnly = True; {Foreach (DatagridViewRow line in dgvLoadTable.Rows) Try {var cellValue = row.Cells [cboCrudSearchColumn.SelectedIndex]. value; If (cell valley! = Null & amp; amp; cellwhicho.Testring () == txtCrudSearch.Text.ToUpper ()) {row.Selected = true; Line. Visible = true; } And row View = false; }} Catch (Exceptions) {message box. Show (exc.message); }}
Comments
Post a Comment