Auto complete in datagridview RRS feed

  • Question

  • how to use auto complete in textbox to display in datagridview using c#.net.

    i will post a link here


    plz help

    Tuesday, March 22, 2016 5:17 AM


All replies

  • Hi,

    Which is which?
    TextBox is a source for user to input, and DataGridView is a target to that will be shown?
    Or when TextBox.Text is changed, it will be replaced customer's name in DataGridView?

    Please inform the further detail.

    Tuesday, March 22, 2016 6:44 AM
  • yes...

    when textbox click event is fired datagridview is displayed with list of customers name and details. if a user type a letter in textbox , the related datas or customer name should be shown in datagridview..means auto complete.

    help me sir plzz...

    so many issues are there in my project..and i have only limited period of time. :(

    Tuesday, March 22, 2016 7:05 AM
  • Hi,

    I suppose...

    handled event is TextBox_TextChanged

    In the event:
     1) know the length of TextBox, i.e. the number of characters which user input.
         suppose it's 3 characters
     2) loop all rows of DataGridView, i.e. from 0 to DataGridView.RowCount -1
         if the first 3 characters in DataGridView(Customer column) = TextBox.Text
             the row of DataGridView is visible
         else         the row of DataGridView is invisible  

    Tuesday, March 22, 2016 7:24 AM
  • Hi,

    How about this?
    (This is only in my mind, not checked with Visual Studio)
    private void textBox1_TextChanged(object sender, EventArgs e)
            //int chrLen = this.textBox1.TextLength;
            for (int myRow = 0; myRow <= this.dataGridView1.RowCount - 1; myRow++)
                string dgvText = this.dataGridView1[0, myRow].Value.ToString();
                if (dgvText.IndexOf(this.textBox1.Text) == 0) 
                        this.dataGridView1.Rows[myRow].Visible = false;
                    else {
                        this.dataGridView1.Rows[myRow].Visible = true;


    • Edited by Ashidacchi Tuesday, March 22, 2016 8:08 AM
    Tuesday, March 22, 2016 7:40 AM
  • not working sir...control is not entering to the textchanged method...
    Tuesday, March 22, 2016 8:53 AM
  • I hope this will be the final trial.
    // --- Text Changed: Incrementary Search
    private void TextBox_TextChanged(object sender, EventArgs e)
    	int txtLen = this.TextBox.Text.Length;
        // --- DataGridView Loop
    	for (int myRow = 0; myRow <= DataGridView.RowCount - 1; myRow++) {
    		DataGridView.Rows(myRow).Visible = false;
    		if ((DataGridView(0, myRow).Value.ToString.Length < txtLen)) {
    		} else {
    			if ((DataGridView(0, myRow).Value.ToString.Substring(0, txtLen) == TextBox1.Text)) {
    				DataGridView.Rows(myRow).Visible = true;
    Wednesday, March 23, 2016 12:55 AM
  •  private void txtCustmrName_TextChanged(object sender, EventArgs e)
                int txtLen = this.txtCustmrName.Text.Length;
                // --- DataGridView Loop
                string unme;
                for (int myRow = 0; myRow <= dguser.Rows.Count - 1; myRow++)
                   dguser.Rows[myRow].Visible = false;
                    if (unme.Length < txtLen)
                    //if ((DataGridView(0, myRow).Value.ToString.Length < txtLen))
                    //    continue;
                        if (unme.Substring(0, txtLen) == txtCustmrName.Text)
                            dguser.Rows[myRow].Visible = true;
    i wrote above code..it shows the following error..

    "Row associated with the currency manager's position cannot be made invisible."

    in below code..

    help me sirr


    Wednesday, March 23, 2016 8:01 AM
  • As far as your first image, "Customer" name is the first column, the second is "Description".
    So, I suppose Cells[0] is correct.


    I'd like to clarify your needs again.
    Please provide some pictures: name(input none, one character, two characters) and each result of DataGridView.
    Wednesday, March 23, 2016 10:37 PM
  • below is my form..


    below is the error


    help me sir .. :(

    Thursday, March 24, 2016 4:34 AM
  • Please explain your needs with using Excel.
    If your needs would be satisfied, how the results would be.
    Please provide some pictures: name(input none, one character, two characters) and each result of DataGridView, with using Excel. 
    Thursday, March 24, 2016 7:08 AM
  • i got a sample for my project. its an executable file.. that is .exe file. my duty is to make a new project from the given sample. 

    i will explain what all things i need.

    i have a datagrid contain three columns..namely "UserID, UserName, Role". UserID will be hidden for the end users. when a forms is loaded this grid is invisible. grid is visible when the textbox named txtcustmr is clicked. grid will display all the records. when the user types any letter in the textbox, the matching UserName should be displayed in the grid. 


    above is the image of grid appears when user click on textbox.


    above is the image of grid appears when user type text in texbox.

    help me sir..

    Thursday, March 24, 2016 8:35 AM
  • How many characters(letter) can be input in the TextBox?
    Only one character? or more than one?
    Thursday, March 24, 2016 8:42 AM
  • any..if user types letters..matching words should be displayed in grid..that is auto complete..
    Thursday, March 24, 2016 9:22 AM
  • Sorry. I cannot/won't follow you further.  Would someone give him/her a help?
    Thursday, March 24, 2016 9:57 AM
  • so sad :(
    Thursday, March 24, 2016 10:10 AM
  • Hi Mousimi Nishad,

    Maybe you could read to your old thread:




    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 28, 2016 5:51 AM