将列表框选中的项插入光标点上的texbox [英] inserting listbox selected items to texbox on cursor point
问题描述
我有两个字段,文本区域和列表框。当我选择列表框中的每个项目时,它必须显示在文本区域中,并在其中附加文本。如果我在一些文本之前移动光标并从列表框中选择另一个项目,它必须附加放置光标的项目。
i更新鲜到这个字段所以请帮助我该怎么办?
i尝试使用此txtTemplatebody.Text = txtTemplatebody.Text + lbTokenList.SelectedItem.ToString();但是当我试图在前面附加它不起作用。
提前谢谢
I have two fields, text area and Listbox. When i select each item in listbox it has to display in text area with appending on the text in it. and if i move the cursor before some text and select another item from listbox it must append the item where the cursor is placed.
i am fresher to this field so please help how do i do it??
i tried with this txtTemplatebody.Text = txtTemplatebody.Text + lbTokenList.SelectedItem.ToString(); but when i tried to append on front it's not working.
Thanks in advance
推荐答案
Here is your complete solution. just check it!If you have any more question feel free to ask.
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{ //code of listbox selectedIndexChanged event
try
{
int si = textBox1.SelectionStart;
textBox1.Text=textBox1.Text.Insert(si,listBox1.SelectedItem.ToString());
textBox1.SelectionStart = si + listBox1.SelectedItem.ToString().Length;
}
catch(Exception ex)
{
throw ex;
}
}
function insert(el, ins) {
if (el.setSelectionRange) {
el.value = el.value.substring(0, el.selectionStart) + ins + el.value.substring(el.selectionStart, el.selectionEnd) + el.value.substring(el.selectionEnd, el.value.length);
}
else if (document.selection && document.selection.createRange) {
el.focus();
var range = document.selection.createRange();
range.text = ins + range.text;
}
}
function Updatelist() {
var sel = document.getElementById(listboxID);
var listLength = sel.options.length;
for (var i = 0; i < listLength; i++) {
if (sel.options[i].selected) {
return sel.options[i].value;
}
}
}
最后添加
listboxid。 Attributes.Add(Onclick,insert(+ txtid.ClientID +,Updatelist()));在.cs页面
Finally add
listboxid.Attributes.Add("Onclick", "insert(" + txtid.ClientID + ",Updatelist())"); in .cs page
这篇关于将列表框选中的项插入光标点上的texbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!