WPF how to get Selected Indices Of ListBOx [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
for (int x = added_signals_listbox.SelectedItems.Count - 1; x >= 0; x--)
{
SignalViewModel SelectedItem = added_signals_listbox.SelectedItems[x] as SignalViewModel;
int SelectedItemIndex = added_signals_listbox.Items.IndexOf(SelectedItem);
//ListBoxItem container = added_signals_listbox.SelectedItems.Item.ContainerFromItem(SelectedItem) as ListBoxItem;
//int SelectedItemIndex = added_signals_listbox.ItemContainerGenerator.IndexFromContainer(container);
_GraphViewerViewModel.AddedSignals.RemoveAt(SelectedItemIndex);
}
The commented code doesn't run, and I don't remember what I was trying to ask yesterday. Sorry about the poor question. I think I must have copy and pasted the wrong code. Please close the question.

Listbox for instance
<ListBox Name="listbox" SelectionChanged="changed" SelectionMode="Multiple">
<ListBox.Items>
<ListBoxItem>one</ListBoxItem>
<ListBoxItem>two</ListBoxItem>
</ListBox.Items>
</ListBox>
private void changed(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
for (int index = 0; index < listbox.SelectedItems.Count; index++)
listbox.Items.Remove(listbox.SelectedItems[index]);
}
When you select any item it will be deleted right away, is that what you wanted to acquire?

Related

Sort float numbers List from small to large [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to sort float numbers List from small to large. I tried to use the array.Sort () method but it doesn't work.
Below is my code.
List<float> array = new List<float>();
array.Add(x);
listBox1.Items.Add(x);
Just Sort():
List<float> array = new List<float>();
array.Add(x);
array.Sort();
When array (quite a strange name for List<float>) is sorted, we can insert x somewhere in the middle of listBox1.Items. Asuming that listBox1.Items contains ordered float items only, we can put
// Here's we have WinForms ListBox
int at = listBox1.Items.Count;
for (int i = 0; i < listBox1.Items.Count; ++i) {
if (x < (float) (listBox1.Items[i])) {
at = i;
break;
}
}
listBox1.Items.Insert(at, x);

I cant increment value by 2 or more than 2 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
How do i increment a value by 2 instead of 1? when i run my code it will go from 1-10 by adding 1 but i want it to go 1-10 by adding 2
for (int x=0;x<10;x++)
{
Console.WriteLine(x);
}
You can do instead -
for (int x = 0; x < 10;) {
Console.WriteLine(x);
x = x + 2;
}
If I understand you correctly, this should be the solution for you.
for (int x = 0; x < 10; x += 2)
{
Console.WriteLine(x);
}

How to set checked item in checkedlistbox with listbox - c# [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have problem to select item from listbox and check item in checkedlistbox.
How can I select item from listbox and then check in checkedlistbox?
I cant select listbox item and check checkedlistbox when match item
I want code for select checklistbox when item in listbox
How can check in checkedlistbox with textbox and seprated comma
if I understand your question right :
What you need is the method GetItemCheckState.
Usage as follows:
Try This :
foreach (var item in listBox1.Items)
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
checkedListBox1.SetItemChecked(i, false);//First uncheck the old value!
//
for (int x = 0; x < listBox1.Items.Count; x++)
{
if (checkedListBox1.Items[i].ToString() == listBox1.Items[x].ToString())
{
//Check only if they match!
checkedListBox1.SetItemChecked(i, true);
}
}
}
}

For int i = value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am trying to create some code that search for a value .
As of now the code looks like :
private void button4_Click(object sender, EventArgs e)
{
uint randBuff = DLL.Extension.ReadUInt32(0x0154d6e4);
for (int i = 0; i < 144705; i++)
{
randBuff = (randBuff + 4);
listBox1.Items.Add(randBuff.ToString("x8"));
}
}
The value I search is 144705 . The idea is to stop searching for the value when randBuff =144705 . Can this be done with a loop or is there any other way to do it ?
If I understand your question right, then this is more appropriate of a loop:
while (randBuff < 144705)
{
listBox1.Items.Add(randBuff.ToString("x8"));
randBuff += 4;
}
Basically, as long randBuff is less than the target value of 144705, add the value to the list box and increase the value by 4.

how to achieve for loop IronPython [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How to achieve this C# for-loop in IronPython, I can't seem to find a way to make i - 10 in IronPython
int amount = 32;
int scrolls = 0;
int mets = 0;
if (amount >= 10) {
for (int i = amount; i >= 10; i -= 10) {
scrolls++;
if (i - 10 < 10)
mets = i - 10;
}
}
Your loop exit condition is i >= 10. Your loop entry condition is amount >= 10. i gets set to your amount on loop entry, which is already >= 10. Your loop will never execute.

Categories

Resources