# How to deselect the text

**URL:** <https://www.ruby-forum.com/t/how-to-deselect-the-text/152584>\
**Category:** wxRuby\
**Created:** [November 5, 2008, 11:14am UTC](https://www.ruby-forum.com/t/how-to-deselect-the-text/152584 "2008-11-05T11:14:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 5, 2008, 11:14am UTC](https://www.ruby-forum.com/t/how-to-deselect-the-text/152584/1 "2008-11-05T11:14:18Z")

</div>

Hi,  
I’m using TextCtrl and initially set some text in it. And all the text  
is  
selected by default.  
How can I deselect it?  
By the way, TextCtrl#set\_selection() doesn’t work… What am I doing  
wrong?

Thanks a lot,  
Kirill.

Here’s the sample:

====================== wxtest.rb ===========================  
require ‘wx’

class TestFrame \< Wx::Frame

def initialize  
super(nil, -1, “Test”)  
text = Wx::TextCtrl.new(self, -1, “first\_line\n”,  
:style =\> Wx::TE\_RICH|Wx::TE\_RICH2|Wx::TE\_MULTILINE)  
text.append\_text “second line”  
text.set\_selection(3, 4)  
end

end

class TestApp \< Wx::App  
def on\_init  
TestFrame.new.show  
end  
end

TestApp.new.main\_loop

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 5, 2008, 12:47pm UTC](https://www.ruby-forum.com/t/how-to-deselect-the-text/152584/2 "2008-11-05T12:47:01Z")

</div>

ÐšÐ¸Ñ€Ð¸Ð»Ð» Ð›Ð¸Ñ…Ð¾Ð´ÐµÐ´Ð¾Ð² wrote

> I’m using TextCtrl and initially set some text in it. And all the text  
> is selected by default.  
> How can I deselect it?  
> By the way, TextCtrl#set\_selection() doesn’t work… What am I doing  
> wrong?

Thanks for reporting this and providing a clear test case. I’ve tried it  
out and it seems to be a bug, specific to Windows. I was a bit surprised  
as I’m fairly sure this used to work.

If you’re able, please could you file this on the bug tracker and attach  
your example as a test case. This will be a MUSTFIX for 2.0.

By the way, if you’re using RICH and RICH2 for formatting, you might see  
if RichTextCtrl works better for you. TextCtrl + RICH2 has some  
cross-platform quirks, although it will be better for accessibility I  
guess.

thanks  
alex

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 5, 2008, 1:09pm UTC](https://www.ruby-forum.com/t/how-to-deselect-the-text/152584/3 "2008-11-05T13:09:52Z")

</div>

> > Thanks for reporting this and providing a clear test case. I’ve tried it  
> > out and it seems to be a bug, specific to Windows. I was a bit surprised as  
> > I’m fairly sure this used to work.
> 
> If you’re able, please could you file this on the bug tracker and attach  
> your example as a test case. This will be a MUSTFIX for 2.0.

Done:  
[http://rubyforge.org/tracker/index.php?func=detail&aid=22686&group\_id=35&atid=218](http://rubyforge.org/tracker/index.php?func=detail&aid=22686&group_id=35&atid=218)

And it also didn’t work in 1.9.8, I just didn’t pay attention to it at  
that  
time.

By the way, is it also a bug that the whole text is selected by default?

By the way, if you’re using RICH and RICH2 for formatting, you might see  
if

> RichTextCtrl works better for you. TextCtrl + RICH2 has some cross-platform  
> quirks, although it will be better for accessibility I guess.

I’m not sure that I need all the power provided by RichTextCtrl, it  
looks  
that for my task simple TextCtrl is just fine. But I’ll try, thanks for  
pointing to it.

Regards,  
Kirill.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 5, 2008, 6:14pm UTC](https://www.ruby-forum.com/t/how-to-deselect-the-text/152584/4 "2008-11-05T18:14:16Z")

</div>

Kirill L. wrote:

> Done:  
> [http://rubyforge.org/tracker/index.php?func=detail&aid=22686&group\_id=35&atid=218](http://rubyforge.org/tracker/index.php?func=detail&aid=22686&group_id=35&atid=218)  
> [http://rubyforge.org/tracker/index.php?func=detail&aid=22686&group\_id=35&atid=218](http://rubyforge.org/tracker/index.php?func=detail&aid=22686&group_id=35&atid=218)

Thanks

> And it also didn’t work in 1.9.8, I just didn’t pay attention to it at  
> that time.
> 
> By the way, is it also a bug that the whole text is selected by default?

Yes, I think so. It doesn’t do this on other platforms.

a
