我写了一个小工具,主要是显示一个listview 弄成一个表格的模样,然后我想实现双击修改某一格子中的内容,但是现在没法实现,把labeledit 属性设置为true也没有用,,因为内容是从网页上抓取的,而不是从数据库中提取的,所以没用datagridview,就像求问大神们 ,应该怎样才能完成双击修改的问题。拜谢了
解决方案 »
- 求解释:对象浏览器与从原数据两者有何区别?
- 问一个关于entity的问题
- excle数据导入到sql server数据库中,该如何实现
- C# 调用 C++ 的 DLL
- 把datatabel给datagridview后,为什么rows是0呢
- C#从web导出word
- .net来路是怎么判断的呢???
- 关于往panel中动态加一些控件,控件不能重叠,当有的控件被删除后,腾出来的地方还可以加控件 ,求此算法。
- 求助时间格式转换的问题
- c# 创建分布式对象(SQLDMO.dll不能加入到.net中)
- C#中如何把int转换成两个字符的string?
- object oMissing = System.Reflection.Missing.Value是什么意思?
//获取鼠标点击的项------API
[DllImport("user32")]
public static extern int GetScrollPos(int hwnd, int nBar); private TextBox txtInput; //获取点击项的位置
private void lViewPersonWork_MouseDoubleClick(object sender, MouseEventArgs e)
{
try
{
ListViewItem item = this.lViewPersonWork.GetItemAt(e.X, e.Y); //找到文本框
Rectangle rect = item.GetBounds(ItemBoundsPortion.Entire);
int StartX = rect.Left; //获取文本框位置的X坐标
int ColumnIndex = 0; //文本框的索引 //获取列的索引
//得到滑块的位置
int pos = GetScrollPos(this.lViewPersonWork.Handle.ToInt32(), 0);
foreach (ColumnHeader Column in lViewPersonWork.Columns)
{
if (e.X + pos >= StartX + Column.Width)
{
StartX += Column.Width;
ColumnIndex += 1;
}
} if (ColumnIndex < this.lViewPersonWork.Columns.Count - 1)
{
return;
} this.txtInput = new TextBox(); //locate the txtinput and hide it. txtInput为TextBox
this.txtInput.Parent = this.lViewPersonWork; //begin edit
if (item != null)
{
rect.X = StartX;
rect.Width = this.lViewPersonWork.Columns[ColumnIndex].Width; //得到长度和ListView的列的长度相同
this.txtInput.Bounds = rect;
this.txtInput.Multiline = true;
//显示文本框
this.txtInput.Text = item.SubItems[ColumnIndex].Text;
this.txtInput.Tag = item.SubItems[ColumnIndex];
this.txtInput.KeyPress += new KeyPressEventHandler(txtInput_KeyPress);
this.txtInput.Focus();
}
}
catch (Exception ex)
{
}
} //回车保存内容
private void txtInput_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if ((int)e.KeyChar == 13)
{
if (this.txtInput != null)
{
ListViewItem.ListViewSubItem lvst = (ListViewItem.ListViewSubItem)this.txtInput.Tag; lvst.Text = this.txtInput.Text; this.txtInput.Dispose();
}
}
}
catch (Exception ex)
{
}
} //释放文本框内容
private void lViewPersonWork_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (this.txtInput != null)
{
if (this.txtInput.Text.Length > 0)
{
ListViewItem.ListViewSubItem lvst = (ListViewItem.ListViewSubItem)this.txtInput.Tag; lvst.Text = this.txtInput.Text;
} this.txtInput.Dispose();
}
}
catch (Exception ex)
{
}
}以上就是实现双击ListView单元格在当前单元格上显示一个一样大小的文本框,输入文字之后回车保存并释放掉文本框,以及在不回车的情况下双击其他单元格时释放文本框