Is it possible to find a record in a datagrid by typing characters into the grid? Bascially if I have the following records:
Anne
Bob
Bill
Bud
Carl
Carlos
Curt

And type "C" it will got to the records that start with "C". If I type "Ca" it will go to the records that start with the corresponding characters.

I cannot find anything on the subject, but not be using the right terminology. If someone knows an efficient way to do this or knows of a site that explains it I would appreciate it.

Thanks :)

are you binding data from database to data grid?
using LIKE '%" c "%' operator to do this.

I already have every record I need in the grid... When you start typing it should go to the row that has the same characters you are typing (based off the primary key).

I already have every record I need in the grid... When you start typing it should go to the row that has the same characters you are typing (based off the primary key).

Does that make sense or do I need to elaborate?

I have a grid with all of the information that I need from the DB. The company name is the primary key. When the page with the grid comes up I would like to be able to type characters and it will go to the row that most closely matches what I type.

Like I mentioned before if I had the following records:
Anne
Bob
Bill
Bud
Carl
Carlos
Chris
Curt

And type "C" it will jump down to the first row with "C" for the company name (Carl for this example). If I type "Ch" it will go to the row with "Ch" in it (Chris for this example).

Does that make better sense?

why you don't make search function to searching data by name and display all data in grid.
ex : C -> all employee with name include c will display on grid. more specific input will display specific data.

I have a grid with all of the information that I need from the DB. The company name is the primary key. When the page with the grid comes up I would like to be able to type characters and it will go to the row that most closely matches what I type.

Like I mentioned before if I had the following records:
Anne
Bob
Bill
Bud
Carl
Carlos
Chris
Curt

And type "C" it will jump down to the first row with "C" for the company name (Carl for this example). If I type "Ch" it will go to the row with "Ch" in it (Chris for this example).

Does that make better sense?

ok......i understood...now try the following steps :- (for testing)

1. take one ADODC, one DATAGRID, one TEXTBOX control on your form.
2. this code is tested on sql server database. so create a sample database "COMPANY" and inside it create a table "DETAILS" with three fields :-
COMPANY_NAME (VARCHAR PRIMARY KEY)
ADDRESS (VARCHAR)
PHONE (NUMBER)
3. now make connection with the ADODC control to the sql server database.
4. connect the DATAGRID with the ADODC control
5. now in the CHANGE event of the TEXTBOX control paste the following code :-

[B]Private Sub Text1_Change()[/B]
If Adodc1.Recordset.RecordCount > 0 Then Adodc1.Recordset.MoveFirst
Adodc1.RecordSource = "details where upper(company_name) like '%" & UCase(Trim(Text1.Text)) & "%'"
Adodc1.Refresh
[B]End Sub[/B]

now execute the program. it will display all records from the table into the grid. now just type any character into the textbox and you will see the filtered data appearing into the grid. as you said, if you type 'C' or 'c' it will jump to the first row of company names starting their name with first character as 'C'. or if you type 'Ch' it will display only the record of 'Chris' into the datagrid.

for your consideration i have also included a screenshot of the output that i got when filtering data by typing a few letters into the textbox. check to see if this fulfills your problem or not.

please don't forget to give me a feedback.

regards
Shouvik

Attachments Screenshot.JPG 66.69 KB

Hi Choudry,

What if i want to get the record sorted based on the char i enter. instead of filtering, i want the records to be sorted according to the char enterted in the text box.

Thanx
Shiva

ok......i understood...now try the following steps :- (for testing)

1. take one ADODC, one DATAGRID, one TEXTBOX control on your form.
2. this code is tested on sql server database. so create a sample database "COMPANY" and inside it create a table "DETAILS" with three fields :-
COMPANY_NAME (VARCHAR PRIMARY KEY)
ADDRESS (VARCHAR)
PHONE (NUMBER)
3. now make connection with the ADODC control to the sql server database.
4. connect the DATAGRID with the ADODC control
5. now in the CHANGE event of the TEXTBOX control paste the following code :-

[B]Private Sub Text1_Change()[/B]
If Adodc1.Recordset.RecordCount > 0 Then Adodc1.Recordset.MoveFirst
Adodc1.RecordSource = "details where upper(company_name) like '%" & UCase(Trim(Text1.Text)) & "%'"
Adodc1.Refresh
[B]End Sub[/B]

Shouvik

Hi,
I'm sorry but please help me with this one,

Private Sub Text1_Change()
If Adodc1.Recordset.RecordCount > 0 Then Adodc1.Recordset.MoveFirst
Adodc1.RecordSource = "details where upper(supplier_name) like '%" & UCase(Trim(Text1.Text)) & "%'"
Adodc1.Refresh

End Sub


I have an error when I type a string in this textbox

"INVALID SQL statement; expected 'DELETE', 'INSERT' , 'PROCEDURE' , 'SELECT' or 'UPDATE' "


I don't understand why ... please help me

Edited 6 Years Ago by LordOne: n/a

This article has been dead for over six months. Start a new discussion instead.