将文本框的内容添加到列表视图的已编辑列中 [英] Adding content of textbox into edited column in listview

查看:78
本文介绍了将文本框的内容添加到列表视图的已编辑列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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==&quot;&quot;)
{
MessageBox.Show(&quot;field cant be empty&quot;);
}
else{
hitinfo.SubItem.Text = textBox12.Text;
textBox12.Hide();

}

}</pre>
this code will display the entered textbox value to the listview selected column.



thanks,


这篇关于将文本框的内容添加到列表视图的已编辑列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆