c# List view focus
<p>I have a problem in focusing the listview.In my form i have a listview which contains two columns(Question_text, question_id).When a button is get clicked(Show button) a dialog box is get opened and it show show the selected question_text and question_id.Right now i am able to show the information in the dialog box.But the problem only occurs only when i close the dialog box,the focus on the list view is gone.I what the focus to remain on the same item of list view after closing the dialog box.Can any one help me.Thanks in advance.</p>

<p>Ok this is my code.</p>

<p>There i am reading getting the selected item question id using the listview1_selectionIndexchanged();</p>

<pre><code>     private void btnAdd_Question_Click(object sender, EventArgs e)
    {
        //Add Question Dialog box is shown
        add.ShowDialog();
    }

    private void btnEdit_Question_Click(object sender, EventArgs e)
    {
        //Getting the listview selected Item
        for (int i = 0; i &lt; listView1.SelectedItems.Count; i++)
        {

            String a1 = listView1.SelectedItems[i].Text;
            int b1 = listView1.SelectedIndices[i];
            //Open the connection
             myConnection = new SqlConnection(@"User ID=sa;Password=password123;Initial Catalog=dishtv;Persist Security Info=True;Data Source=ENMEDIA-EA6278E\ENMEDIA");
            try
            {

                myConnection.Open();
                String start_time = string.Format("SELECT Question_text  from otvtbl_question where question_id={0}", a1);
                com = new SqlCommand(start_time, myConnection);
                dr = com.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        now = DateTime.Now;
                     //Getting the start time and convert into date time Format
                       String a = dr["question_id"].ToString();
                       date = Convert.ToDateTime(a);



                    }
                    myConnection.Close();
                }
                //If data and time is greater then current time then allow the 
               // Edit question dialog box to launch
                if (date &gt; now)
                {
                    edit.question_id = a1;

                    edit.ShowDialog();
                }
                else
                {
                    MessageBox.Show("you cant edit this question");
                }




            }

            //Catch the Exceptional error
            catch (Exception ex)
            {
                MessageBox.Show("Error while Deleteing the Data" + ex);
            }

        }

    }
</code></pre>

<p>After that i am calling a another form and showing the information.Here i created a class edit.showdialog() to launch a dialog box.</p>

<p>In my edit dialog box:</p>

<p>Here I am passing  the question_id from the main form to dialog box and displaying the question_text in the dialog box.When the cancel button is get clicked then the dialog box get closed.But the focus is not remaining on the same item in list view.Once again i click on edit button for editing without selecting the item in list view it select the previous one automatically without showing the focus on it.</p>

<p>public String question_id;</p>

<p>private void Edit_Question_Load(object sender, EventArgs e)
        {</p>

<pre><code>        EditData();
    }



   public void EditData()
    { 
         myConnection = new SqlConnection(@"User ID=sa;Password=password123;Initial Catalog=dishtv;Persist Security Info=True;Data Source=ENMEDIA-EA6278E\ENMEDIA");
           myConnection.Open();
            String question = string.Format("SELECT question_text from otvtbl_question where question_id={0}", question_id);
            com = new SqlCommand(question, myConnection);
            dr = com.ExecuteReader();

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    //Assign to your textbox here   
                    txtQuestion.Text = dr["question_text"].ToString();
                }
            }
            myConnection.Close();

     private void btnCancel_Click_1(object sender, EventArgs e)
    {

        this.Close();
    }
</code></pre>
