ListBox 中怎样实现 KeyPress事件 Delete ListBox 中怎样实现 KeyPress 事件 Delete 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在<body>中加入onload="initbox();"<script type="text/javascript">function initbox(){ var opt=document.getElementById("listbox的ID").getElementsByTagName("OPTION"); for(var i=0;i<opt.length;i++){ opt[i].onkeypress=function {optkeypress(this);}; }}function optkeypress(Obj){//这里是你要的操作 alert('abc');}</script>随手写的代码,没有调试,只是个大概意思,有问题再说吧 private void listBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Delete) { if (listBox1.SelectedItem != null) { listBox1.Items.Remove(listBox1.SelectedItem); } } } private void listBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete) { if (listBox1.SelectedItem != null) { listBox1.Items.Remove(listBox1.SelectedItem); } } }注意, KeyPress是指输入字符如果用户按下方向键、功能键是不会触发KeyPress事件的, 所以, 上面的KeyPress事件中, 只能检测到数字键盘的Del(也就是小数点键), 而不能检测到功能键Delete, 这时候, 也只能用KeyDown来辅助 呵,你写的是服务端代码,我的是客户端的,也不知道人家想要什么,唉,现在人问个问题都好懒,都不想说清楚,....ps:keypress是不认识delete的,如果要必须用keydown或keyup 请教一个C#里调用C++写的dll的问题 应用程序如何使用图片呢? 调试问题 请教一个关于“未将对象引用设置到对象的实例”的问题 datagridview问题 如何把List<T>转换为DataGridView的一列 将 varchar 值 '32.00%' 转换为数据类型为 int 的列时发生语法错误。 向C#中插入图片会被后面插入的文字覆盖,如何解决。。在线等。。 像素的处理 SharePoint、OpenERP、ArasPLM GridView的select command问题 winform中 datagrid分组
<script type="text/javascript">
function initbox(){
var opt=document.getElementById("listbox的ID").getElementsByTagName("OPTION");
for(var i=0;i<opt.length;i++){
opt[i].onkeypress=function {optkeypress(this);};
}
}
function optkeypress(Obj){
//这里是你要的操作
alert('abc');
}
</script>
随手写的代码,没有调试,只是个大概意思,有问题再说吧
private void listBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Delete)
{
if (listBox1.SelectedItem != null)
{
listBox1.Items.Remove(listBox1.SelectedItem);
}
}
} private void listBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
if (listBox1.SelectedItem != null)
{
listBox1.Items.Remove(listBox1.SelectedItem);
}
}
}注意, KeyPress是指输入字符如果用户按下方向键、功能键是不会触发KeyPress事件的, 所以, 上面的KeyPress事件中, 只能检测到数字键盘的Del(也就是小数点键), 而不能检测到功能键Delete, 这时候, 也只能用KeyDown来辅助
ps:keypress是不认识delete的,如果要必须用keydown或keyup