CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Posts
    2

    Listview Sub Item Edit

    Hi,

    Can anyone trace out where is the error




    lstListView.DoubleClick += new EventHandler(this.lstEditDoubleClick);
    txtSubItem.KeyPress += new KeyPressEventHandler(this.txtEditOver);
    lstListView.MouseDown += new MouseEventHandler(this.lstEditMouseDown);

    public void lstEditMouseDown(object sender, MouseEventArgs e)
    {
    ListViewItem item = lstListView.GetItemAt(e.X, e.Y);
    X = e.X;
    Y = e.Y;
    }

    private void lstEditDoubleClick(object sender, EventArgs e)
    {

    int nStart = X;
    int spos = 0;
    int epos = lstListView.Columns[0].Width;

    for (int i = 0; i < lstListView.Columns.Count; i++)
    {
    spos = epos + X;
    epos += lstListView.Columns[3].Width;
    }

    subItemText = lstListView.SelectedItems[0].SubItems[3].Text;

    Rectangle r = new Rectangle(spos, lstListView.SelectedItems[0].SubItems[3].Bounds.Y, epos, lstListView.SelectedItems[0].SubItems[3].Bounds.Bottom);
    txtSubItem.Size = new System.Drawing.Size(epos - spos, lstListView.SelectedItems[0].SubItems[3].Bounds.Bottom - lstListView.SelectedItems[0].SubItems[3].Bounds.Top);
    txtSubItem.Location = new System.Drawing.Point(spos, lstListView.SelectedItems[0].SubItems[3].Bounds.Y);
    txtSubItem.Show();
    txtSubItem.Text = subItemText;
    }

    private void txtEditOver(object sender, KeyPressEventArgs e)
    {
    if (e.KeyChar == 13)
    {
    lstListView.SelectedItems[0].SubItems[3].Text = txtSubItem.Text;
    txtSubItem.Hide();
    }

    if (e.KeyChar == 27)
    txtSubItem.Hide();
    }

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Listview Sub Item Edit

    We're not debuggers. Give us a real question to answer, tell us what you have tried, what the problem is. Also, please use code tags.

  3. #3
    Join Date
    Jan 2009
    Posts
    2

    Re: Listview Sub Item Edit

    Hi,
    Here I am trying to edit value in lstListView.SelectedItems[0].SubItems[3] column.
    The textbox I have placed is not displayed at that coulmn position. I have done with all the possibilites but unable to place the textbox in required Location.

  4. #4
    Join Date
    Mar 2007
    Posts
    274

    Re: Listview Sub Item Edit

    Hi, you need to first determine the top and left edge values for the container of your listview (this may be a form if it is, then ignore these values). Next you determine the left and top edge of the listview. Now you get the listview items .position property and use the listview.item.columns[?].width property to determine how far over to go. Based on that you can calculate where to position your text box.
    Last edited by Traps; January 29th, 2009 at 03:34 AM.

  5. #5
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: Listview Sub Item Edit


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured