用户按键preSS搜索的DataGridView [英] Search datagridview on user keypress

查看:111
本文介绍了用户按键preSS搜索的DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图选择第一行所在的单元格值以相同的keychar用户pressed。这是给我的麻烦的部分。

I'm trying to select the first row where the cell value starts with the same keychar the user pressed. That's the part that is giving me trouble.

下面是我如何处理事件(更新工作液):

Here's how I'm handling the event (updated with working solution):

private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (Char.IsLetter(e.KeyChar))
    {
        for (int i = 0; i < (dataGridView1.Rows.Count); i++)
        {
    	    if (dataGridView1.Rows[i].Cells["Name"].Value.ToString().StartsWith(e.KeyChar.ToString(), true, CultureInfo.InvariantCulture))
    	    {
    		    dataGridView1.Rows[i].Cells[0].Selected = true;
    		    return; // stop looping
    	    }
        }
    }
}

我敢肯定这件事情简单的说我俯瞰,但对我的生活不能弄清楚它是什么。

I'm sure it's something simple that I'm overlooking, but for the life of me can't figure out what it is.

更新了code与解决方案,适用

Updated the code with solution applied

推荐答案

可能是一个问题的情况下,是在细胞中的价值[名称]以大写字母?尝试使用ToUpper的或TOLOWER两个;或者你可以尝试StartsWith(e.KeyChar,真),以IGNORECASE。如果你想选择该行,你会想要做dataGridView1.Rows [I] .Selected = TRUE

Might be a case issue, is the Value in Cells["Name"] start with a capital letter? Try using ToUpper or ToLower on both; or you could try StartsWith(e.KeyChar, true) to ignoreCase. If you are trying to select the row, you'll want to do dataGridView1.Rows[i].Selected = true

这篇关于用户按键preSS搜索的DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆