Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5981453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:56:45+00:00 2026-05-22T21:56:45+00:00

I have a problem in focusing the listview.In my form i have a listview

  • 0

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.

Ok this is my code.

There i am reading getting the selected item question id using the listview1_selectionIndexchanged();

     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 < 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 > 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);
            }

        }

    }

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

In my edit dialog box:

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.

public String question_id;

private void Edit_Question_Load(object sender, EventArgs e)
{

        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();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:56:46+00:00Added an answer on May 22, 2026 at 9:56 pm
    private void btnAdd_Question_Click(object sender, EventArgs e)
    {
        var focusedItem = listView1.FocusedItem;
        add.ShowDialog();
        listView1.FocusedItem = focusedItem;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with show or hide form in Window Form Application. I start
I have a jDialog which contains some fields that need to get focused. I
I have the following problem in ASP.NET: there is a form that contains a
I have seen some related questions but none focusing on the specific problem I
I have problem SIMILAR to preventing form data reposting, but not quite the same
I'm trying to get a .toggleClass working on a form that I have multiple
I am making an CSS button and I am focusing a problem right now.
I have a Calculator which opens on focusing on the text box. This Calculator
I have a search form on which I have the following INPUT field <input
I have problem on deleting component which is created on runtime. Please help me.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.