0

This is how I have a listView: PICTURE

For example, I have clicked on the 6th row (which is colored blue) and with a double click I want to insert "SomeName" into a 2nd column (called 1.rezervacija) beside the 9:30. How to do it so?

I need something else, with if statement, like

if(listView1.SelectedItem[0] and a 2nd column (1.rezervacija) is empty)
then insert a name,
else create a new column (2.rezervacija) and insert "SomeName"

I was trying with this, but it is not working (I got into Text the actually hour from the 1st column, instead the text from the 2nd column):

if (listView1.SelectedItems[0].SubItems[0].Text == String.Empty)
{
    //SubItems.Add() code
}

Edited by Mitja Bonca: n/a

3
Contributors
2
Replies
6
Views
7 Years
Discussion Span
Last Post by DdoubleD
0

SubItems[0].Text is the text in the first column, use SubItems[1].Text
So Line 1 of your code checks the first row of your ListView.

1

As ddanbe said, and you can use the FindItemWithText method to retrieve the corresponding item:

private void SetReservation(string time, string reservation)
        {
            // find item with matching time...
            ListViewItem item = listView1.FindItemWithText(time);
            if (item != null)
            {
                // Set value for reservation column...
                item.SubItems[1].Text = reservation;
            }
        }
Votes + Comments
He! did not know that. Thanks :)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.