| | |
Search and Select on Datagrid
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
Hi All
I am having a problem on finding a solution regarding the ff problem
I need to do a search using a textbox and a datagrid, that means type in a text on the textbox and press enter and If a record is found the datagrid should point to the found record. I want to emphasize that a record has been found in the datagrid by highlighting the entire row
Can anyone help me with the code or how can I achieve that
Thanks in advance
I am having a problem on finding a solution regarding the ff problem
I need to do a search using a textbox and a datagrid, that means type in a text on the textbox and press enter and If a record is found the datagrid should point to the found record. I want to emphasize that a record has been found in the datagrid by highlighting the entire row
Can anyone help me with the code or how can I achieve that
Thanks in advance
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
•
•
Join Date: Jul 2009
Posts: 903
Reputation:
Solved Threads: 144
0
#2 Oct 20th, 2009
Here is an example of searching a DataGrid: How to implement a searchable DataGrid...
To select the row, of course:
To select the row, of course:
dataGrid1.Select(int rowId); •
•
Join Date: Jul 2009
Posts: 903
Reputation:
Solved Threads: 144
0
#3 Oct 20th, 2009
Here is a crude example I built from that link I gave:
EDIT--NOTE: I do not
C# Syntax (Toggle Plain Text)
public partial class Form_DataGrid : Form { DataTable dt; DataView dv; CurrencyManager CM; public Form_DataGrid() { InitializeComponent(); } private void Form_DataGrid_Load(object sender, EventArgs e) { dt = BuildDynamicTableArrayExample(); dv = new DataView(dt); dataGrid1.DataSource = dv; dv.Sort = "FieldName1"; // sort field required for search (Find)... // Initialize CurrencyManager to hold an instance of the form's CurrencyManager. // Needed to manipulate the row pointer... CM = (CurrencyManager)dataGrid1.BindingContext[dv]; } private void button1_Click(object sender, EventArgs e) { int row = dv.Find(textBox1.Text); // find the text... if (row >= 0) { CM.Position = row; // position the row pointer... dataGrid1.Select(row); // if wanting to highlight the row too... } } public static DataTable BuildDynamicTableArrayExample() { // Create new DataTable object... DataTable dt = new DataTable(); dt.TableName = "MyDataTable"; // Optional unless serializing datatables // Add some columns to the table... dt.Columns.Add(new DataColumn("FieldName1", typeof(string))); dt.Columns.Add(new DataColumn("FieldName2", typeof(int))); dt.Columns.Add(new DataColumn("FieldName3", typeof(double))); // Optional primary key field specifier... dt.Columns["FieldName1"].Unique = true; // generate some rows of data... for (int r = 0; r < 10; r++) { // create a row object of table object's type defined above DataRow dr = dt.NewRow(); // Set each column value in the row... dr["FieldName1"] = "data " + r; dr["FieldName2"] = r; dr["FieldName3"] = (double)r; // add the row to the table dt.Rows.Add(dr); } return dt; } }
EDIT--NOTE: I do not
UnSelect(int rowID) any rows and although it will move the row pointer every time, it will also leave the previous row highlighted. Last edited by DdoubleD; Oct 20th, 2009 at 2:41 pm.
![]() |
Similar Threads
- Search and Desplay on DataGrid (ASP.NET)
- Select Datagrid row (ASP.NET)
- How to select value in datagrid and use it to retrive records from database (VB.NET)
- help:how to select a record in MSH flexgrid (Visual Basic 4 / 5 / 6)
- need help setting up a php/mysql search (PHP)
- bringing data from mysql using select box (PHP)
- select statemt LIKE (MySQL)
- Windows Search Not Functioning (Windows NT / 2000 / XP)
Other Threads in the C# Forum
- Previous Thread: merge sort and quick sort
- Next Thread: zkemkeeper.dll C# error connection
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client combobox connection console control conversion csharp custom database datagrid datagridview dataset datetime degrees deployment developer development draganddrop drawing editing encryption enum event excel file form format forms function gdi+ hospitalmanagementinformationsystem httpwebrequest image imageprocessing index input install java label list listbox mandelbrot math mouseclick mysql operator oracle path photoshop picturebox pixelinversion post priviallages. programming radians regex remote remoting richtextbox rows serialization server sleep socket sql statistics stream string table temperature text textbox thread time timer txt update uploadatextfile usercontrol validation visualstudio webbrowser windows windowsformsapplication winforms wpf xml





