Click here to Skip to main content
15,893,487 members
Home / Discussions / C#
   

C#

 
GeneralRe: Listbox suggestion from textbox Pin
dudz artiaga18-Aug-13 15:25
dudz artiaga18-Aug-13 15:25 
GeneralRe: Listbox suggestion from textbox Pin
SaqibRasheed19-Aug-13 2:45
SaqibRasheed19-Aug-13 2:45 
GeneralRe: Listbox suggestion from textbox Pin
BillWoodruff19-Aug-13 11:52
professionalBillWoodruff19-Aug-13 11:52 
AnswerRe: Listbox suggestion from textbox Pin
BillWoodruff18-Aug-13 14:12
professionalBillWoodruff18-Aug-13 14:12 
GeneralRe: Listbox suggestion from textbox Pin
dudz artiaga18-Aug-13 15:27
dudz artiaga18-Aug-13 15:27 
GeneralRe: Listbox suggestion from textbox Pin
BillWoodruff19-Aug-13 12:05
professionalBillWoodruff19-Aug-13 12:05 
AnswerRe: Listbox suggestion from textbox Pin
TnTinMn19-Aug-13 17:14
TnTinMn19-Aug-13 17:14 
GeneralRe: Listbox suggestion from textbox Pin
BillWoodruff20-Aug-13 17:48
professionalBillWoodruff20-Aug-13 17:48 
Thumbs Up | :thumbsup: Interesting work TnTinMn !

I really enjoyed studying your code, and seeing what you did with a DataSet, and the AutoComplete filter, thanks.

There are, however, some structural problems I see with your solution:

1. a ListBox has no 'AutoSize property: you never adjust its height, so, unless its height is equal to the possible maximum height (sum of the heights of all matches) of any possible single-character match, which, imho is undesirable visually. Then:

2. if the ListBox Height is too "short" to accommodate all the items of a given match: you will have to use the up-down selector at the ListBox right, to scroll to get to see all the possible matches. imho, that's an unacceptable burden on the user.

3. your solution will work for a single character entered at the start of a TextBox only.

4. when the TextBox is cleared, all the choices are displayed.

5. if you enter two spaces, followed by a valid letter, like "a" in this case, no choices appear.

If you modify your code like this:
C#
// original code by TnTinMn
// modified by bw ... Aug. 21, 2013
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
    // note that for this to work the UserControl must have 'AutoSize set to 'true !

    // * modified by bw ... Aug. 21, 2013
    // quit if the TextBox is empty
    // make sure the ListBox is not visible
    if (string.IsNullOrWhiteSpace(textBox1.Text))
    {
        if (listBox1.Visible) listBox1.Visible = false;
        return;
    }
    //*

    // original code by TnTinMn
    // note the single quote usage in the filter
    // see: http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx
    autocompletelist.DefaultView.RowFilter = "[item] LIKE '" + textBox1.Text + "*'";

    // * original code by TnTinMn
    // commented out by bw ... Aug. 21, 2013
    // listBox1.Visible = autocompletelist.DefaultView.Count > 0;
    // *

    // * modified by bw ... Aug. 21, 2013
    if (autocompletelist.DefaultView.Count > 0)
    {
        listBox1.Visible = true;

        // make sure the ListBox expands to shows all possible matches !
        listBox1.Height = (autocompletelist.DefaultView.Count + 1) * listBox1.ItemHeight;
    }
    else
    {
        listBox1.Visible = false;
    }
    //*
}
Now the user will see all the possible matches, filtered as you would expect, but the control's behavior still has the other problems mentioned above: with the code as it is now.

While your solution is "fun," haven't you duplicated the function of a ComboBox ?

yours, Bill

~
“This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal

GeneralRe: Listbox suggestion from textbox Pin
TnTinMn21-Aug-13 4:34
TnTinMn21-Aug-13 4:34 
QuestionSotware Template for manage SMEs Pin
Member 990191217-Aug-13 7:48
Member 990191217-Aug-13 7:48 
AnswerRe: Sotware Template for manage SMEs Pin
Dave Kreskowiak17-Aug-13 11:40
mveDave Kreskowiak17-Aug-13 11:40 
AnswerRe: Sotware Template for manage SMEs Pin
Mycroft Holmes17-Aug-13 13:54
professionalMycroft Holmes17-Aug-13 13:54 
AnswerRe: Sotware Template for manage SMEs Pin
Abhinav S17-Aug-13 17:16
Abhinav S17-Aug-13 17:16 
GeneralRe: Sotware Template for manage SMEs Pin
Member 990191218-Aug-13 5:01
Member 990191218-Aug-13 5:01 
GeneralRe: Sotware Template for manage SMEs Pin
Dave Kreskowiak18-Aug-13 7:32
mveDave Kreskowiak18-Aug-13 7:32 
QuestionHow To access inner Control in custom user control Pin
Mahdi_kishislan17-Aug-13 0:11
Mahdi_kishislan17-Aug-13 0:11 
AnswerRe: How To access inner Control in custom user control Pin
Ron Beyer17-Aug-13 4:03
professionalRon Beyer17-Aug-13 4:03 
GeneralRe: How To access inner Control in custom user control Pin
OriginalGriff17-Aug-13 4:55
mveOriginalGriff17-Aug-13 4:55 
GeneralRe: How To access inner Control in custom user control Pin
Mahdi_kishislan17-Aug-13 20:15
Mahdi_kishislan17-Aug-13 20:15 
GeneralRe: How To access inner Control in custom user control Pin
OriginalGriff17-Aug-13 21:20
mveOriginalGriff17-Aug-13 21:20 
GeneralRe: How To access inner Control in custom user control Pin
Mahdi_kishislan17-Aug-13 20:15
Mahdi_kishislan17-Aug-13 20:15 
AnswerRe: How To access inner Control in custom user control Pin
OriginalGriff17-Aug-13 4:56
mveOriginalGriff17-Aug-13 4:56 
AnswerRe: How To access inner Control in custom user control Pin
Pete O'Hanlon17-Aug-13 6:54
mvePete O'Hanlon17-Aug-13 6:54 
Questiontcp ip Pin
Member 360103416-Aug-13 21:56
Member 360103416-Aug-13 21:56 
AnswerRe: tcp ip Pin
Mycroft Holmes16-Aug-13 23:11
professionalMycroft Holmes16-Aug-13 23:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.