By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,964 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,964 IT Pros & Developers. It's quick & easy.

Listview Sub Item Edit

P: 18
Hi,
Can anyone trace out where is the error

Expand|Select|Wrap|Line Numbers
  1. lstListView.DoubleClick += new EventHandler(this.lstEditDoubleClick);
  2. txtSubItem.KeyPress += new KeyPressEventHandler(this.txtEditOver);
  3. lstListView.MouseDown += new MouseEventHandler(this.lstEditMouseDown);
  4. public void lstEditMouseDown(object sender, MouseEventArgs e)
  5.         {
  6.             ListViewItem item = lstListView.GetItemAt(e.X, e.Y);
  7.             X = e.X;
  8.             Y = e.Y;
  9.         }
  10. private void lstEditDoubleClick(object sender, EventArgs e)
  11.         {
  12.             int nStart = X;
  13.             int spos = 0;
  14.             int epos = lstListView.Columns[0].Width;
  15.             for (int i = 0; i < lstListView.Columns.Count; i++)
  16.             {
  17.                 spos = epos + X;
  18.                 epos += lstListView.Columns[3].Width;
  19.             }
  20.             subItemText = lstListView.SelectedItems[0].SubItems[3].Text;
  21.             Rectangle r = new Rectangle(spos, lstListView.SelectedItems[0].SubItems[3].Bounds.Y, epos, lstListView.SelectedItems[0].SubItems[3].Bounds.Bottom);
  22.             txtSubItem.Size = new System.Drawing.Size(epos - spos, lstListView.SelectedItems[0].SubItems[3].Bounds.Bottom - lstListView.SelectedItems[0].SubItems[3].Bounds.Top);
  23.             txtSubItem.Location = new System.Drawing.Point(spos, lstListView.SelectedItems[0].SubItems[3].Bounds.Y);
  24.             txtSubItem.Show();
  25.             txtSubItem.Text = subItemText;
  26.         }
  27.         private void txtEditOver(object sender, KeyPressEventArgs e)
  28.         {
  29.             if (e.KeyChar == 13)
  30.             {
  31.                 lstListView.SelectedItems[0].SubItems[3].Text = txtSubItem.Text;
  32.                 txtSubItem.Hide();
  33.             }
  34.             if (e.KeyChar == 27)
  35.                 txtSubItem.Hide();
  36.         }
Jan 27 '09 #1
Share this Question
Share on Google+
3 Replies


100+
P: 179
What is the error? If it's somewhere in there try debugging it, otherwise you'll need to give more information.
Jan 28 '09 #2

Curtis Rutland
Expert 2.5K+
P: 3,256
I'm afraid we can't...we are here to help you help yourself, not to do your job for you.

Debug it, find the exact line with the error, and post the line and error message.

If it is a logic error, rather than a syntax error, describe what it is supposed to do versus what it is doing.

MODERATOR
Jan 28 '09 #3

P: 18
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.
Is that clear..
Jan 28 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.