簡體   English   中英

我在自動完成方面遇到麻煩

[英]I'm having trouble with auto complete

感謝您閱讀我的問題,我正在嘗試為文本框設置自動完成功能,但我沒有得到想要的功能,我想我的linq一定有問題
這是我的密碼

 private AutoCompleteStringCollection GetLinqDataSourceForString(string p)
    {
        var c = new AutoCompleteStringCollection();
        c.Add(p + Getauto(txtSearch.Text));
        return c;
    }

private void txtSearch_TextChanged(object sender, EventArgs e)
    {
        txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
        txtSearch.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
        txtSearch.AutoCompleteCustomSource = GetLinqDataSourceForString(txtSearch.Text);
    } 

這是我的linq,應該從數據庫中獲取數據

    public string AutoUpdate(string _search)
    {
        using (var context = new Phone_BookEntities1())
        {
            var c = (from d in context.Cantacts
                     where d.Cantact1 == _search
                     select d.Cantact1).SingleOrDefault();
            return c;
        }
     }

我的問題在哪里? 請幫忙,Tnx

如果我們寫(cat),它將輸入(catcat)

p + Getauto(txtSearch.Text)解釋說,您可能不想在此處附加p ,而Getauto應該使用p代替

當我們鍵入(c)它應該帶貓時,它不會給我們任何選擇,但不會,您必須鍵入所有單詞

那么你where做一個完整的比較

where d.Cantact1 == _search

這可能需要使用StartsWith

where d.Cantact1.StartsWith(_search)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM