从DataGrid/ListBox控件在TextBox中插入一些值后清除“选择" [英] Clear Selection after inserting some values in TextBox from DataGrid/ListBox Control

查看:86
本文介绍了从DataGrid/ListBox控件在TextBox中插入一些值后清除“选择"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某些文本框中传递了ListBox/DataGrid值
当我将文本框对准焦点时,所有文本均显示为蓝色.
要清除此问题,我开始使用TextBox.Select(0,0)清除选择
但是当我使文本框聚焦时,我发现光标从0位置开始.
我希望光标位于字符串的末尾而没有选择.

帮助我

I Passed a ListBox/DataGrid Value in some Textbox
When I focused Textbox the all text appears selected blue.
To Clear this problem I start to use TextBox.Select(0,0) to clear Selection
but I found cursor on starting 0 position when I focused textbox.
I want cursor at end of string without selection.

Help Me

推荐答案

SelectionLength设置为0.将SelectionStart设置为文本长度减一.

最好使用属性System.Windows.Forms.TextBoxBase.TextLength http: //msdn.microsoft.com/zh-CN/library/system.windows.forms.textboxbase.textlength.aspx [
Set SelectionLength to 0. Set SelectionStart to the text length minus one.

It''s the best to use the property System.Windows.Forms.TextBoxBase.TextLength, http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.textlength.aspx[^] for best performance, but it works only for Forms. For other UI libraries, use Text.Length, which can be slow if the text is very big. Hopefully, it won''t be a problem for you.

—SA


这篇关于从DataGrid/ListBox控件在TextBox中插入一些值后清除“选择"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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