
Nguyên bản được gửi bởi
thanhhai_al
vấn đề ở đây là mình không biết có bao nhiêu số trong chuổi mình nghĩ nên dùng cách lấy mã ascii của kí tự nhưng mình không biết dùng hàm nào để lấy mong chỉ giúp
còn cái listview thì khi ấn phím hoặc button thì cái vệt xanh mới di chuyển
ai biết chỉ giúp mình với
Bạn thử cái này. Đoạn code dưới đây giả định bạn đã có một textBox1 và listView1 control (thuộc tính CheckBoxes đặt true để hiện ô checkbox cho các item). Bạn cũng có thể sửa lại một chút để dùng cho sự kiện textBox1_TextChanged nếu muốn làm giống Lạc Việt từ điển, nghĩa là cho các Item phù hợp trong listView xuất hiện tức thì mỗi khi text trong textBox1 thay đổi.
PHP Code:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((char)Keys.Enter == e.KeyChar)
{
string strLetter = "";
string strDigit = "";
String objStr = textBox1.Text;
int intLength = objStr.Length;
if ("" != objStr)
{
//MessageBox.Show(objStr.Length.ToString());
for (int i = 0; i < intLength ; i++)
{
if (!Char.IsDigit(objStr[i]))
{
strLetter += objStr[i];
}
else
{
strDigit += objStr[i];
}
}
}
//Chuoi so sau khi filter
textBox1.Text = strDigit;
if ("" != strLetter)
{
MessageBox.Show(objStr + " = " + strLetter + " + " + strDigit);
}
//Xu ly listView
int j = 0;
for ( j = 0; j < listView1.Items.Count; j++ )
{
//MessageBox.Show(textBox1.Text.ToString() + " __ " + listView1.Items[j].Text.ToString());
if (textBox1.Text.ToString() == listView1.Items[j].Text.ToString())
{
listView1.Items[j].Selected = true;
listView1.Items[j].Checked = true;
listView1.Items[j].Focused = true;
listView1.Items[j].EnsureVisible();
listView1.Focus();
break;
}
}
DialogResult dlResult = new DialogResult();
dlResult = MessageBox.Show("Ban co muon xoa Item nay khong?", "Info", MessageBoxButtons.YesNo);
if (DialogResult.Yes == dlResult)
{
listView1.Items.RemoveAt(j);
listView1.Refresh();
}
}
}