I have a RadListBox which has 11 items. And I need to have the first 7 items as static which means they shouldn't be reordered. I have written the below javascript and it works just fine.
The 8th item in listbox is still movable(up) and this shouldn't happen. I need to reorder the items only after 7th item till 11th item and only within themselves. Means out of 11 items, first 7 items order should be static and from 8 to 11 these fields can be reordered.
Can anyone suggest how this can be achieved?
HTML:
<telerik:RadListBox ID="RadListBox" runat="server"
AllowReorder="true OnClientSelectedIndexChanging="RadListBox_Reordering"/>
JS:
function RadListBox_Reordering(sender, eventArgs) {
var value = eventArgs.get_item().get_value();
if (value == "Item1" || value == "Item2" || value == "Item3" || value == "Item4" || value == "Item5" || value == "Item6" || value == "Item7") {
eventArgs.set_cancel(true);
}
}
You can use the OnClientDropping event, which is cancelable, to detect where the reordered item is landing.
function OnClientDroppingHandler(sender, eventArgs) {
var index = args.get_destinationItem().get_index();
if (index < 8) {
alert('you may not drop on the first 7 items');
args.set_cancel(true);
}
}
https://www.telerik.com/forums/how-to-disable-dragging-dropping-to-first-position
Related
I have this code:
foreach (MyClass info in data)
{
if (info.year!= "" && info.year!= null)
{
TreeViewYear.SelectedNode = TreeViewYear.RootNodes[0].Children.FirstOrDefault(x => x.Content?.ToString() == info.year);
}
}
Imagining that the foreach runs twice with the years "5" and "2", he selects correctly but then when he runs the second time, gets only the 2 value, that is, the value 2 and withdraws the 5.
If you want to select more than one item, you should set the SelectionMode of the TreeView to Multiple and add the items to be selected to the SelectedNodes property:
TreeViewYear.SelectedNodes.Add(
TreeViewYear.RootNodes[0].Children.FirstOrDefault(x => x.Content?.ToString() == info.year));
I am new to coding and more so c#, on and off have been picking it at. Trying to learn by doing very basic projects in my spare time and am trying to figure out why I am not getting a result when both radios out of two are unchecked. The simple idea is if both radios are unchecked write a simple string to a list. Of course I can easily see both or one or the other and get two written indexes to the list, one for each. I am trying to see why I can't get just one list add if both are unchecked:
foreach (var child in children)
{
if (child.GetType() == typeof(TextBox))
{
UserText.Add("TXT BOX11");
}
if (child.GetType() == typeof(RadioButton))
{
if (((((RadioButton)child).Name == "Radio1") && ((RadioButton)child).IsChecked == false)
&& ((((RadioButton)child).Name == "Radio2") && ((RadioButton)child).IsChecked == false))
{
UserText.Add("Pickles");
}
}
}
You are only ever checking the current child. Since your condition is both ((RadioButton)child).Name == "Radio1" and ((RadioButton)child).Name == "Radio2" it will never be true.
You might want to use the CheckedChanged event instead or just access the radiobuttons through their variables. Probably named something like radioButton1 and radioButton2.
Lastly, if it has to be within the foreach loop you could set an external variable to keep track.
bool otherButton = false;
foreach (var child in children)
{
// textbox code
if(child is RadioButton rbtn && rbtn.Name == "Radio1" && rbtn.IsChecked == false)
{
if(otherButton)
UserText.Add("Pickles");
else
otherButton = true;
}
if(child is RadioButton rbtn && rbtn.Name == "Radio2" && rbtn.IsChecked == false)
{
if(otherButton)
UserText.Add("Pickles");
else
otherButton = true;
}
}
"I understand question title may be repeated but did not find a solution which I am looking for."
A groupbox which contains approx 50 controls in the combination of textboxes and comboBoxes. I have to set value for them and don't want to write 50 individual lines to set value for each control, so I came up with below code. But this is not working in case of comboboxes. OR If you guys can suggest something better that would be great.
if(controlsInGroupBox == editStep.Count)
{
int i = 0;
foreach (Control ctr in universalGroupBoxObject.Controls)
{
if (ctr is TextBox)
{
ctr.Text = editStep[i];
}
if (ctr is ComboBox)
{
//ctr.SelectedIndex = cntrlObjListMain.comboBoxLocation.FindStringExact(editStep[i]);
//ctr.SelectedIndex is not working
}
i++;
}
}
If you databind your data to the combobox then the first item is selected by default saving you having to select one.
E.G.
List<string> items = new List<string>() { "aa", "bb", "cc", "dd" };
combobox1.DataSource = items;
SelectedIndex should work as long as you have items in your list.
ctr.SelectedIndex = ctr.Items.Count > 0 ? 0 : -1;
The above will select an item if there are any items, otherwise won't select anything.
What is ListBox SelectedIndex Equivalent in ListView ?
How i can write the below code in ListView ?
if(listbox.SelectedIndex == -1)
{
}
There are two ways to check if you have an item selected
if(listview.SelectedItems.Count > 0)
{
}
or
if(listview.SelectedIndices.Count > 0)
{
}
If multisect is true you could have more than one element in this collections else only the Item selected
How can I check if no items "At all" selected from listview?
Thanks.
if( myListView.SelectedItems == null || myListView.SelectedItems.Count == 0 )
{
}
See ListView..::.SelectedItems Property for more info.
EDIT: As per the MSDN documentation:
If no items are currently selected, an
empty
ListView..::.SelectedListViewItemCollection
is returned.
So the null check is not needed in this case and you can simply do:
if( myListView.SelectedItems.Count == 0 )
{
}