I would like to be able to initialize a LINQPad SelectBox (MultiSelect) by specifying the indexes to be selected initially.
I would like to be able to initialize a LINQPad SelectBox (MultiSelect) by specifying the indexes to be selected initially. Could we get SelectBox.SetSelectedIndexes( int[] indices ) and SelectBox.MergeSelectedIndexes( int[] indices ) methods?
I think to understand this will require some JavaScript coding. Please refer to my sample below:
private string _mergeSelectedIndexesScript = @"function mergeSelectedIndexes(id, indices) {
var select = document.getElementById(id);
var options = select && select.options;
var opt;
var found;
for (var i=0, iLen=options.length; i<iLen; i++) {
opt = options[i];
found = false;
for (var j=0, jLen=indices.length; j<jLen; j++) {
if (indices[j]== i) {
opt.selected = true;
break;
}
}
}
return;
}";
private void _setSelectedIndexesScript = @"function setSelectedIndexes(id, indices) {
var select = document.getElementById(id);
var options = select && select.options;
var opt;
var found;
for (var i=0, iLen=options.length; i<iLen; i++) {
opt = options[i];
found = false;
for (var j=0, jLen=indices.length; j<jLen; j++) {
if (indices[j]== i) {
found=true;
break;
}
}
opt.selected = found;
}
return;
}";
-
You can already set selected indexes as follows:
var box = new SelectBox (SelectBoxKind.MultiSelectListBox, "one", "two", "three").Dump();
box.SelectedIndexes = new[] { 0, 1, 2};