关于在datagrid列中搜索字符串的问题 [英] Question regarding searching string in datagrid column

查看:77
本文介绍了关于在datagrid列中搜索字符串的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在研究一种分配,以在datagridview列中搜索值,如果值与输入文本框匹配,则datagrid光标应移动到具有该搜索值的单元格,并且如果该列具有多个搜索值,则光标应移动到具有该特定值的下一个单元格搜索的值,等等.例如
----------
column1
----------
ANATR
安东
AROUT
BERGS
AROUT
BLONP
AROUT
BONAP
---------
假设如果我们在用户第一次按下serch按钮时搜索位于3月5日,5月和7日单元格中的值AROUT,则数据网格光标应移至第3个单元格,而当用户再次单击搜索按钮时,datagrid光标应移至3号单元格.第五个单元格,当用户第三次单击搜索按钮时,数据网格光标应移至第七个单元格
我已经尝试过使用FOR循环和IF条件进行许多组合
但是使用以下代码,如果条件不允许我多次搜索一个值,则我只能搜索一次字符串,代码是

hi all,
i am working on an assignment to search a value in datagridview column if value matched with input textbox then datagrid cursor should move to the cell having that searched vallue and if column has more than one searched values then cursor should move to next cell having that particular searched value and so on .e.g
----------
column1
----------
ANATR
ANTON
AROUT
BERGS
AROUT
BLONP
AROUT
BONAP
---------
suppose that if we search for value AROUT which is in cell nomber 3,5 and 7 when user hit the serch button first time then data grid cursor should move to the 3rd cell and when user again click search button then datagrid cursor should move to the 5th cell and when user click search button third time then datagrid cursor should move to the 7th cell
i have tried many combination with FOR loop and IF condition
but with following code i am able to search the string only once obviously if condition does not allow me to search a value more than once .the code is

for i as integer=1 to 90
If DataGridView1.CurrentCell.Value<>textbox1.text Then
                DataGridView1.CurrentCell = DataGridView1.Item(0, i + 1)
            End If
            Next


推荐答案

您是否尝试过使用while循环?
在当前单元格上继续前进,直到找到该值或没有更多单元格为止.
Have you tried using a while loop?
Go forward on the current cell until you find the value or you have no more cells.


这篇关于关于在datagrid列中搜索字符串的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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