浏览 1664 次
锁定老帖子 主题:我的程序员行程
精华帖 (0) :: 良好帖 (0) :: 灌水帖 (0) :: 隐藏帖 (1)
|
|
---|---|
作者 | 正文 |
发表时间:2009-05-07
最后修改:2009-05-07
Point position = Point.Empty; private void lsBFilter_MouseMove(object sender, MouseEventArgs e) { position = new Point(e.X, e.Y); int i = 0; for (i = lsBFilter.Items.Count - 1; i > 0; i--) { if (position.Y >= i * lsBFilter.ItemHeight) { lsBFilter.SetSelected(i, true); break; } if (position.Y < lsBFilter.ItemHeight) { lsBFilter.SetSelected(0, true); } } } private void txtBookName_MouseClick(object sender, MouseEventArgs e) { lsBFilter.ClearSelected(); lsBFilter.Visible = false; } 第一次使用文本框和listbox实现方便的数据库查询 private void txtBookName_TextChanged(object sender, EventArgs e) { cboBook.SelectedIndex = -1; cboClass.SelectedIndex = -1; cboUsers.SelectedIndex = -1; lsBFilter.Items.Clear(); if (txtBookName.Text.Trim() != "") { strSql = string.Format("select DISTINCT Booksname from BookInfo where Booksname like '%{0}%'", txtBookName.Text.Trim()); DBHelper.getDataTableA(strSql); int i = 0; while (DBHelper.NumF.Length > 0 && i < DBHelper.NumF.Length) { lsBFilter.Items.Add(DBHelper.NumF[i]); i++; } if (DBHelper.NumF.Length > 0) { lsBFilter.SetBounds(txtBookName.Location.X, txtBookName.Location.Y + txtBookName.Height, txtBookName.Width, 4 * txtBookName.Height); lsBFilter.ScrollAlwaysVisible = false; lsBFilter.Visible = true; } lsBFilter.SetSelected(0, true); } if (txtBookName.Text.Trim() == "") { lsBFilter.Items.Clear(); lsBFilter.Visible = false; } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |