我正在創(chuàng)建一個(gè)桌面聊天應(yīng)用程序,用戶可以在其中按姓名或電子郵件搜索其他用戶。當(dāng)我搜索其他用戶時(shí),他們的圖像不是按順序排列的。// 這是來(lái)自 Home Form 的代碼 private void BtnSearch_Click(object sender, EventArgs e) { if (Friends.SelectedIndex == 0) { UsersClass.SearchContacts(listAllContacts, ImgListAllContacts, TxtSearch.Text.Trim()); } }// 這是來(lái)自 UserClass 的代碼 public static void SearchContacts(ListView listview, ImageList imagelist, string searchkey) { DataTable dt = new DataTable(); listview.Items.Clear(); ListViewItem[] listviewitem = null; dt = DataBaseAccess.Retrive("select UID,FullName,DP from TKDBUsers WHERE ( FullName+' '+UserName ) Like '%" + searchkey + "%' AND UID != '" + LogInUser.UID + "'"); if (dt != null) { if (dt.Rows.Count > 0) { listviewitem = new ListViewItem[(dt.Rows.Count)]; int LC = 0; //List contacts foreach (DataRow item in dt.Rows) { Image img = DataBaseAccess.Base64ToImage(Convert.ToString(item["DP"])); imagelist.Images.Add(img); listviewitem[LC] = new ListViewItem(new string[] { Convert.ToString(item["UID"]) + " - " + Convert.ToString(item["FullName"]) }, LC); LC++; } } } if (listviewitem != null) { listview.Items.AddRange(listviewitem); }在此處輸入圖像描述在此處輸入圖像描述
2 回答

幕布斯6054654
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超7個(gè)贊
嘗試將選擇查詢更改為(添加“ORDER BY UserName”):
dt = DataBaseAccess.Retrive("
SELECT UID, FullName, DP
FROM TKDBUsers
WHERE (FullName+' '+UserName ) LIKE '%" + searchkey + "%'
AND UID != '" + LogInUser.UID + "'
ORDER BY UserName");
- 2 回答
- 0 關(guān)注
- 102 瀏覽
添加回答
舉報(bào)
0/150
提交
取消