We have a tool that is being integrated into our application. We have some strict borders around us too in that we cannot modify the application except for our extensions. I have searched here, I've searched the internet, but cannot find any postings about this problem.
I have a Windows Form that contains a ListView and our user requires we create a checkbox to Select/Deselect all. I have the event handler for when the check box state changes and call the routine to set everything to Selected.
private void SelectAllEventHandler(object sender, EventArgs e)
{
ChangeState(RadCapListView, SelectAllRadcap.Checked);
}
private void ChangeState(SWF.ListView control, bool state)
{
if (control.CheckBoxes)
{
control.Items.OfType<SWF.ListViewItem>().ToList()
.ForEach(item => item.Checked = state);
}
else
{
control.Items.OfType<SWF.ListViewItem>().ToList()
.ForEach(item => item.Selected = state);
}
control.Refresh();
}
Going into debug mode all items are marked as selected.
Also at the control level SelectedItems is properly updated.
The issue is that visually the control just will not highlight the selected items like we have our WPF forms doing. As you can see in the code I also tried to refresh the control hoping that would show items selected, but no joy.
Has anyone solved this problem in getting selected items to display properly?
Thank!
Instead of using control.Refresh(), try control.Focus().
Related
I have created an app. One of the features in the app is making a list and saving to Isolated Storage.
To the point, my problem is with deleting items from the list. To clarify, the user of the app can add items to list, and then save it. I am also using a LongListMultiSelector, which I downloaded from the web. What happens here is you can check items in a special boxes that pops-up (LongListMultiSelector feature). Up to this point, every feature works well. I want the user to be able to check the checkboxes, and press delete button, much like Windows Phone Hotmail, and rid of them. This is the part where I am having trouble.
So I click the trash can button which should function as a delete button. I have the following code for it.
private void button3_Click(object sender, EventArgs e)
{
while (LLMS.SelectedItems.Count > 0)
{
source.Remove((MainList)LLMS.SelectedItems[0]);
InitializeComponent();
}
}
LLMS represents the LongListMultiSelector.
MainList is class and the list.
What happens is the app freezes up and stops working, though no pop-up comes up.
You can use this lines of code:
void OnRemoveClick(object sender, EventArgs e)
{
IList source = MainList.ItemsSource as IList;
while (MainList.SelectedItems.Count > 0)
{
source.Remove((**ObjectName**)MainList.SelectedItems[0]);
}
}
I have above scenario: If user click on ListBox, it will either have sub items (again ListBox) or detail view.
So what i did currently is: Whenever user clicks any item, made a web call and filled up the same ListBox if clicked item is having further sub items.
Now, issue comes in picture:
Suppose i am in 4th screen (detail view),
Moved to the 3rd and 2nd screen with data maintained as stack (Its working fine, yes i am maintaining data in ObservableCollection<ObservableCollection<MyObjects>> so while moving back, i am fetching data from there)
Now, if i click any item in screen 2, it will open detail view for the screen 3 ListBox data.
Means that ListBox is not getting notified that we have filled data inside OnBackKeyPress()
FYI, i am filling up ListBox and WebBrowser in the same page., so my problem is that how do i notify ListBox once i filled up data from stack which i have maintained?
Yes i have also implemented INotifyPropertyChanged but don't know why its not working.
Please check my code:
ListBox and WebView screen: http://pastebin.com/K1G27Yji
RootPageItem class file with the implementation of INotifyPropertyChanged: http://pastebin.com/E0uqLtVG
sorry for pasting code in above way, i did as question is being long.
Problem:
How do i notify ListBox that data is changed from OnBackKeyPress?
And what is the behavior if you set:
listBox1.ItemsSource = null;
before
listBox1.ItemsSource = listRootPageItems;
This is just wrong architecture. Instead of reloading the same listbox, please add a single page for each screen. Share data between them inside the App class (internal static) and use the built in navigation stack for handling "going back". Don't override OnBackKeyPress for this purpose.
You will get your desired functionality for "free" with easier to maintain and use codebase.
Oops it was a silly mistake i made.
I forgot to set items[] array inside OnBackKeyPress() but was accessing while clicking item, hence its having items[] data of last step we moved in forward direction, it was executing the same data.
Now, i have just included a single line and it has solved my problem.
items = listRootPageItems.ToArray(); // resolution point
So final code of onBackKeyPress() is:
/**
* While moving back, taking data from stack and displayed inside the same ListBox
* */
protected override void OnBackKeyPress(CancelEventArgs e)
{
listBox1.Visibility = Visibility.Visible;
webBrowser1.Visibility = Visibility.Collapsed;
listBox1.SelectedIndex = -1;
if (dataStack.Count != 0)
{
listBox1.ItemsSource = null;
listRootPageItems = dataStack[dataStack.Count-1];
listBox1.ItemsSource = listRootPageItems;
items = listRootPageItems.ToArray(); // resolution point
dataStack.Remove(listRootPageItems);
e.Cancel = true;
}
}
I am using UltraDropDown control to bind a column of one UltraGrid control to list People category in list format.
This drop-down control have more than 25 items and show 8 categories Max, it's very fine. Now whenever I click on drop-down control to see all people category list then i have to hold scroll bar and drag down to see all categories. but I want to show all categories when I mouse scroll and its automatically move up and down to show all, and one more thing I want, when i mouse hover on listed categories then hover item should be shaded or colored.
Please help on both topic.
Thanks & Regards,
Shashi Bhushan Jaiswal
I believe that the first requirement is by default as behavior. Are you handling the MouseWheel event for this to not work?
Here is the code for your second requirement but I do not know if it is a good approach to use the MouseHover event as you like but this is your requirement:
void ultraDropDown1_MouseHover(object sender, EventArgs e)
{
if (cell != null && isInItem) {cell.Cell.Appearance.BackColor = Color.Red;}
}
CellUIElement cell;
bool isInItem = false;
private void ultraDropDown1_MouseEnterElement(object sender, Infragistics.Win.UIElementEventArgs e)
{
if (e.Element is EditorWithTextDisplayTextUIElement && e.Element.Parent.Parent is CellUIElement)
{
cell = (CellUIElement)e.Element.Parent.Parent;
isInItem = true;
}
else isInItem = false;
}
currently I'm developing an app for WP7 but came across a little problem with a Listbox event call Selection_Change. The problem is that when i return to the page that contains the listbox the selection_change event triggers without being changed at all or without any user input. The listbox code is similar to this:
private void lsbHistory_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = lsbHistory.SelectedIndex;
NavigationService.Navigate(new Uri("/Views/NextPage, UriKind.Relative));
}
On the page I navigate to, the only way out of the navigated page is by pressing back button or start button meaning that it will return to the page that contains the listbox. When I Navigate back the selection change triggers leading me sometimes to a exception. Has anyone been through this before?
Consider always checking if it's -1 (the default value).
private void lsbHistory_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = lsbHistory.SelectedIndex;
if (index != -1)
{
NavigationService.Navigate(new Uri("/Views/NextPage, UriKind.Relative));
lsbHistory.SelectedIndex = -1; // Set it to -1, to enable re-selection.
}
}
Also, you should consider wrapping the Navigate call in Dispatcher.BeginInvoke to have a better, more smooth, page transition.
The event will be fired when the list is populated.
The simplest solution for you will probably be to add a check that there is nothing selected before triggering your navigation:
if (lsbHistory.SelectedIndex > -1)
{
// do navigation
}
One thing to notice is that when you navigate back to the page which containt the ListBox, the ListBox still has the SelectedItem set to the value it had when the user navigated away. This means that lsbHistory.SelectedIndex will get the index of the item which was selected when the user navigated forward.
Maybe there's something in your code which presumes that the ListBox's SelectedItem is null when the user navigates to the page?
I've seen similar questions asked about WPF, but none of the proposed solutions seem to work under Windows Phone 7.
Basically, I've got a listbox where the behavior needs to be
1) when user taps an item in the list, it's selected.
2) when user taps any other item, the first is unselected and the tapped item is selected (so far this is just normal single select list box behavior)
3) when user taps an already selected item, the item "unselects" (so that there is no selected item at all anymore).
It's certainly easy enough to intercept the MouseLeftButtonDown event and clear the selection, but the ui system appears to continue processing the tab and turns around an reselects the item I've just unselected.
At first, I thought binding could be the problem, and the list items +are+ bound to an observableCollection, but neither the "selectedItem" or "selectedIndex" are bound at all.
I tried setting the event args handled prop to true:
e.Handled = true
but no change.
Any ideas?
Use MouseLeftButtonUp() rather than MouseLeftButtonDown().
private object _selected;
private void ListBox_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
var list = (ListBox) sender;
if (list.SelectedItem == _selected)
{
list.SelectedIndex = -1;
_selected = null;
}
else
{
_selected = list.SelectedItem;
}
}