我们可以使用“Text LIKE something”在if else条件下 [英] Can we use "Text LIKE something" in if else condition

查看:111
本文介绍了我们可以使用“Text LIKE something”在if else条件下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i在我的程序中使用listview项目中的双击事件......

在该列表项中,其中一列包含这样的值

COLUMN1

   IN 123

   IN 234

   IN 342

   OU 232

   OU 556



我需要的操作当我双击IN 123时,应打开一个关于IN的表格

当我双击OU 232时,应显示另一个关于OU的表格,

for这个即时通讯使用for循环和我用于此的代码是..




i am using double click event in listview items in my program...
in that listitems, one of the columns contains values like this
COLUMN1
   IN 123
   IN 234
   IN 342
  OU 232
  OU 556

the operation i need is when i double click on IN 123 one form regarding IN should be opened
and when i double click on OU 232, another form regarding OU should be displayed,,
for this im using for loop and the code i used for this is..

private void listView1_DoubleClick(object sender, EventArgs e)
{
      if (listView1.Items[2].Text=="IN")
      {
          Stock_Card_Drill_Stock_In scds = new Stock_Card_Drill_Stock_In();
          scds.Show();
      }
      else if(listView1.Items[2].Text=="OU")
      {
          Stock_Card_Drill_Stock_Out scdo=new Stock_Card_Drill_Stock_Out();
          scdo.show();
      }
            
}



但这段代码不能正常工作..请你帮我解决这个问题.. ??


but this code is not working.. can you please help me to solve this..??

推荐答案

感谢您的回复,我用以下代码解决了自己...



thanks for the reply and i solved myself with the following code...

string item1;
item1 = listView1.Items[listView1.FocusedItem.Index].SubItems[2].Text;
if (item1.StartsWith("IN"))
{
   Stock_Card_Drill_Stock_In scds = new Stock_Card_Drill_Stock_In();
   scds.Show();
}
if (item1.StartsWith("OU"))
{
   MessageBox.Show("OU is displayed");
}


你可以使用 String.StartsWith方法(字符串) [ ^ ]



you can use String.StartsWith Method (String)[^]

if (listView1.Items[2].Text.StartsWith("IN")) {
{

}else if(listView1.Items[2].Text.StartsWith("OU")
{

}

您好Chaitanya,



您的列表视图项目类似于IN 123或OU 232,因此,您是否尝试这样:

Hi Chaitanya,

Your list view items are like IN 123 or OU 232, hence, did you try like this:
if(listView1.Items[2].Text.Contains("IN"))



您可以使用Contains()并检查该项是否具有IN或OU,根据您可以编写逻辑。或者你可以使用字符串拆分功能或正则表达式来匹配你的标准。



希望这有帮助!! :) :)



问候,

Praneet


You can use Contains() and check that if that item has IN or OU, based on which you can write your logic. Or you can use string split functions or a regular expression to match your criteria.

Hope this helps !! :) :)

Regards,
Praneet


这篇关于我们可以使用“Text LIKE something”在if else条件下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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