| | |
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: 901
Reputation:
Solved Threads: 141
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: 901
Reputation:
Solved Threads: 141
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 algorithm api array asp.net barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ httpwebrequest image index input install java label libraries list listbox loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql mysql.data.client operator path photoshop php picturebox pixelinversion platform post programming radians regex remoting resourcefile richtextbox server sleep socket sql statistics stream string study system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf xml





