Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why does this code work for my textbox besides the datagridview, but not the textbox in the datagridview?
I have puzzeled and searced for almost 2 hours now. Everything says this should work

C#
private void dgvFunn_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (this.dgvFunn.CurrentCell.ColumnIndex == this.dgvFunn.Columns["Virkestoff"].Index)
            {

                if (Snacks.acscVirkestoff == null)
                {
                    Snacks.acscVirkestoffFyll();
                }

                tbAntKvartaler.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                tbAntKvartaler.AutoCompleteSource = AutoCompleteSource.CustomSource;

                TextBox cbo = new TextBox();
                cbo = (TextBox)e.Control;
                cbo.AutoCompleteMode = AutoCompleteMode.Append;
                cbo.AutoCompleteSource = AutoCompleteSource.CustomSource;
                cbo.AutoCompleteCustomSource = Snacks.acscVirkestoff;

                tbAntKvartaler.AutoCompleteCustomSource = Snacks.acscVirkestoff;
            }
        }
Posted

Why are you creating a new Textbox only to reassign it in the next line?

TextBox cbo = new TextBox();
cbo = (TextBox)e.Control;


C#
TextBox cbo = (TextBox)e.Control;


I assume you have debugged and varified e.Control is a textbox. What is happening? "This doesn't work" isn't very descriptive or helpful.
 
Share this answer
 
Comments
MrDeej 25-Nov-11 7:39am    
I have changed the cbo reassigning. Dont know what i was thinking her.

By it doesnt work i mean that when i start typing in datagridview cell from column "Virkestoff" the autocomplete is not working. But when i type in tbAntKvartaler it does autocomplete for me.

I have used exactly this code on other datagridview in other project, and i cant understand why this does not work
MrDeej 25-Nov-11 7:41am    
the type of e.control is DataGridViewTextBoxEditingControl
Still having problems with this. This seems very odd.

C#
private void dgvFunn_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            TextBox te = e.Control as TextBox;
            te.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            te.AutoCompleteCustomSource.AddRange(new string[] { "one", "two", "three" });
            te.AutoCompleteSource = AutoCompleteSource.CustomSource;
            

        }



Still wont work for me, no autocomplete when i punch the letter o in any columns, it runs trough this code but does nothing in the UI
 
Share this answer
 
v2
m***** f*****.

Finally i solves this sh*t. If the wrapmode on the defaultcellstyle is set to true, you cannnot autocomplete with above code. Setting wrapmode false is the (stupid) solution

so many hours i have used on this!
 
Share this answer
 
Also found a problem where one of several similar datagridviews wouldn't show autocomplete values, while the others with identical properties did work.

The problem appears to be long string values in the autocomplete data. By restricting the entries to 99 characters length, the problem disappeared. It meant I will have to override the truncated autocomplete value selected by the user with the full length value programatically.

Haven't checked what the length limit is, or whether it is the result of multiple large strings.

VS 2010
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900