Skip to content

Check if array contains certain text, and if so, add the rows to listbox

steve potts

Asked Oct 19, 2012, 3:01 AM EDT1 answer
Share
LinkedInX
hi again all!

last question i promise ;)

i need to check if a string variable exists inside of an array of data.

heres how i currently add., what i would like to do is add them only if the data i have in my string smsName is within that row... any ideas? thank!

C#
            foreach (DataRow row in sentSMS.Rows)
            {
                string rows = string.Format("{0}:{1}:{2}", row.ItemArray[0], row.ItemArray[1], row.ItemArray[2]);


                ListViewItem item1 = new ListViewItem(row.ItemArray[0].ToString(), 0);


                item1.Checked = true;
                item1.SubItems.Add(row.ItemArray[1].ToString());
                item1.SubItems.Add(row.ItemArray[2].ToString());
                listView1.Items.Add(item1);

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    ooo my good old friend karl sorted me out :D
    thanks anyway, heres solution incase useful

    C#
                foreach (DataRow row in sentSMS.Rows)
                {
                    string rows = string.Format("{0}:{1}:{2}", row.ItemArray[0], row.ItemArray[1], row.ItemArray[2]);
    
    
                    string sTest = row.ItemArray[1].ToString();
    
    
                    ListViewItem item1 = new ListViewItem(row.ItemArray[0].ToString(), 0);
    
                    if (sTest.Contains(smsName))
                    {
                        item1.Checked = true;
                        item1.SubItems.Add(row.ItemArray[1].ToString());
                        item1.SubItems.Add(row.ItemArray[2].ToString());
                        listView1.Items.Add(item1);
                    }
                }
                connection.Close();
    0