将文本框的内容添加到列表视图的已编辑列中
问题描述:
我的Windows应用程序中有一个listview.我可以在列表视图中编辑特定的列,并将文本框放置在该位置.
现在,我想将文本框文本添加到列表视图的编辑列中,此应用程序中不涉及数据绑定,下面是我的代码..
I have a listview in my windows application. I am able to edit particular column in listview and place textbox in that position.
Now, I want to add the textbox text into the listview edited column,No databinding involved in this application and my code is below..
void ListView1MouseDoubleClick(object sender, MouseEventArgs e)
{
ListViewHitTestInfo hit=listView1.HitTest(e.X,e.Y);
foreach(ListViewItem mitem in listView1.Items)
{
if (mitem.Selected==true)
{
textBox1.Left = listView1.Left + hit.SubItem.Bounds.Left + 3;
textBox1.Top = listView1.Top + hit.SubItem.Bounds.Top;
textBox1.Width = hit.SubItem.Bounds.Width;
textBox1.Text = hit.SubItem.Text;
textBox1.Visible = true;
textBox1.Focus();
textBox1.SelectAll();
}
}
}
void textBox1LostFocus(object sender, EventArgs e)
{
try
{
//here i want the code for the text to be placed in the listview selected column.
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
预先感谢,
thanks in advance,
答
< pre lang ="cs"> if(textBox12.Text ==&& quot;))
{
MessageBox.Show(& quot;字段不能为空& quot;);
}
其他{
hitinfo.SubItem.Text = textBox12.Text;
textBox12.Hide();
}
}</pre>
此代码会将输入的文本框值显示到listview选定的列.
谢谢,
<pre lang="cs">if(textBox12.Text=="")
{
MessageBox.Show("field cant be empty");
}
else{
hitinfo.SubItem.Text = textBox12.Text;
textBox12.Hide();
}
}</pre>
this code will display the entered textbox value to the listview selected column.
thanks,