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
}

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.

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;
            }
        }
commented: He! did not know that. Thanks :) +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.