I have the DisplayMember and DisplayValue set:
racSchTechs.AutoCompleteDataSource = datatable;
racSchTechs.AutoCompleteDisplayMember =
"Name_Full"
;
racSchTechs.AutoCompleteValueMember =
"id_lanid"
;
but I want to get the "id_lanid" from the items selected. I do not see this functionality.
Thank you!
8 Answers, 1 is accepted
Thank you for writing.
The selected items in the control can be found in the Items collection. Each item contain text and a value, so you can get both the display and the value member.
radAutoCompleteBox1.Items[1]
I hope this helps.
Regards,
Stefan
the Telerik team
How are you suppose to know the item number to get the value
AutoDoorComplete.AutoCompleteDataSource = DoorNameList;
AutoDoorComplete.AutoCompleteDisplayMember = "DoorName";
AutoDoorComplete.AutoCompleteValueMember = "DoorID";
When I select a DoorName I want the selected AutoCompleteValueMember DoorID
DoorID = Convert.ToInt32(AutoUser.Items[0].Value.ToString()); How can this work if I do not know the Items[number] ?
Why is it so hard to get the value when selected ?
As the other user said the "SELECTED Value"
Tommy
Thank you for writing.
RadAutoCompleteBox can have more than one item selected at a time. Please have a look at the attached picture (2013-08-29_0849.png), where the control have three values selected (name0, name2, name9). The selected items are stored in the Items collection of the control, so at this moment it has three items in it. Each item has a Text property which holds the value from the field specified as AutoCompleteDisplayMember and a Value property which holds the value from the field specified as AutoCompleteValueMember. Have a look at image 2013-08-29_0855.png, where you can see the selected items text and values.
I hope that you find this information useful.
Regards,
Stefan
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
I have some items which I want to have them in my radautocompletebox , so I can remove or add items in it . AND I need it to show me the items I had entered before.
thank you in advance
Thank you for writing.
I am not quite sure I understand what is your requirement. However, you can use the formatting event and style some of the tokens with different back color to indicate selection. Alternatively, you can select one or more consecutive items by selecting their text, as demonstrated here: http://www.telerik.com/help/winforms/editors-autocompletebox-caret-positioning-and-selection.html.
If this is not what you need, please provide more details on the precise requirement and I will do my best to help you achieve it.
Regards,
Stefan
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
I believe the OP has the same problem that we have run into:
When we close our form, we want to save the items that are currently selected. This is easy, using the Items collection. We need to save both the Text and the Value.
When we then re-open the form, we need to restore it to the same settings as when it was closed, ie. the AutoCompleteBox should be filled with the same items that were saved when we closed it - both text AND value members of the Items collection. We can easily recreate the slected items with text values, but cannot link the ID values to these entries in the Items collection.
So the question is - how do we restore the Items collection with both Text AND Value to an AutoCompleteBox that were saved previously?
Thank you for writing.
To properly restore the items you need to recreate the same data source and assign it to the autocomplete box. The following example shows how you can save and restore the items using simple csv file. The MyItem class just contains two properties (text and value). The code adds all the items to the autocomplete box when the data source is restored. This is achieved with the Text property:
private
void
radButton1_Click(
object
sender, EventArgs e)
{
selctedItems = radAutoCompleteBox1.Text;
var csv =
new
StringBuilder();
foreach
(var item
in
(BindingList<MyItem>) radAutoCompleteBox1.AutoCompleteDataSource)
{
var first = item.Text.ToString();
var second = item.Value.ToString();
var newLine =
string
.Format(
"{0},{1}{2}"
, first, second, Environment.NewLine);
csv.Append(newLine);
}
File.WriteAllText(
"test.csv"
, csv.ToString());
}
private
void
radButton2_Click(
object
sender, EventArgs e)
{
BindingList<MyItem> data =
new
BindingList<MyItem>();
string
text =
""
;
var reader =
new
StreamReader(File.OpenRead(@
"test.csv"
));
while
(!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(
','
);
data.Add(
new
MyItem()
{
Text = values[0],
Value =
int
.Parse(values[1])
});
text += values[0] +
";"
;
}
radAutoCompleteBox1.AutoCompleteDataSource = data;
radAutoCompleteBox1.AutoCompleteDisplayMember =
"Text"
;
radAutoCompleteBox1.AutoCompleteValueMember =
"Value"
;
radAutoCompleteBox1.Text = text;
}
Could you please check the above code and see if it is suitable for your case? If not could you please specify how this approach is different from your real one?
I am looking forward to your reply.
Dimitar
Telerik