Click to See Complete Forum and Search --> : Listview Sub Item Edit


uday1302
January 27th, 2009, 01:57 PM
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();
}

BigEd781
January 27th, 2009, 02:58 PM
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.

uday1302
January 28th, 2009, 09:59 AM
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.

Traps
January 29th, 2009, 02:31 AM
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.

MadHatter
January 29th, 2009, 02:34 AM
take a look at this: http://www.codeproject.com/KB/list/ListViewEmbeddedControls.aspx