LongListMultiSelector programatic selection - windows-phone

In windows phone I have a LongListMultiSelector control that has multi selection made by the user and the selection is saved in a file.
Then If the user tries to load his selection from the file loads fine and selected items are selected again using IsSelected property.
My question is that Why only visible items are checked while other selected items that are outside the view are unchecked ,How can I make them checked also?

LonglistMultiSelector doesn't load all of the items at startup, loads items that are needed instead (see ItemRealized and ItemUnrealized events). Since some of the items that you want to select are not assigned to UI, you can't select them. You can workaround this by scrolling to that item.
I've used the following code to select all items in a LongListMultiSelector.
foreach (ViewModels.ItemViewModel item in longListMultiSelector.ItemsSource)
{
LongListMultiSelectorItem container = longListMultiSelector.ContainerFromItem(item) as LongListMultiSelectorItem;
if (container == null)
{
// item has't been assigned to UI
longListMultiSelector.ScrollTo(item);
container = longListMultiSelector.ContainerFromItem(item) as LongListMultiSelectorItem;
}
container.IsSelected = true;
}

Related

How to override the default response to a touch for a control in UWP?

Is it possible to override the response to a touch interaction for a control in UWP? For example, for a DataGrid XAML control, the default behavior when a row is tapped is to select this row and deselect all other selected rows. Can this be changed to have the tapped row added to the selection as if the control key was pressed?
EDIT: My solution is for Surface Pro in tablet mode so the user would only interact with the app via touch. So I wanted him to be able to select multiple items using touch only. In the image I added, the default behavior if the user clicks on "Chicken Sandwich" is to deselect "Burger" and select "Chicken Sandwich" unless the CTRL key is held down. However using the CTRL key on Surface device without mouse and keyboard would mean that we will need to have the on-screen keyboard on display which would be a bit cumbersome. I would like instead to change the default behavior where if the user clicks on an unselected item it's added to the selection, and if he clicks on a selected item the item it gets removed from selection (in the example below, "Chicken Sandwich" will be added to the selection on first touch and removed from selection on second tap), so basically same functionality as holding the CTRL key down but without using it.
Based on the document, the DataGrid class provides the behavior that selecting multiple items while holding down the SHIFT or CTRL keys during selection. What you need to do is just to set the SelectionMode property as Extended.
Update:
Please check the following code as a sample:
List<object> selectedItems = new List<object>();
bool flag = false;
private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(flag==false)
{
var item = dataGrid.SelectedItem;
if (selectedItems.Contains(item))
{
selectedItems.Remove(item);
}
else
{
selectedItems.Add(item);
}
flag = true;
dataGrid.SelectedItems.Clear();
foreach(var cur in selectedItems)
{
flag = true;
dataGrid.SelectedItems.Add(cur);
}
}
else
{
flag = false;
}
}

virtual ClistCtrl with checkboxes on displayed report list style

I have an MFC SDI application to display a list of data read from a csv file. So I set up its view to be inherited from CListView and make it a virtual list control. That means I have to use LVS_OWNERDATA as one of its CListCtrl style attributes. Yet I now run into a problem when I have to include Checkboxes in each row of the displayed list. As you might know, LVS_EX_CHECKBOXES can't be used with LVS_OWNERDATA, I therefore create a bitmap file to contain 2 small images of checkbox (selected and de-selected) and toggle them every time the user clicks on the loaded image/icon. I am handling this in OnNMClick method. And I have two problems I would like to ask for your help to solve.
(1) I don't know how to update the virtual list (which is commonly handled in OnLvnGetdispinfo method) so I try this in OnNMClick and find that the check and unchecked images aren't toggled.
void CMFCSDITest::OnNMClick(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
LVHITTESTINFO hitinfo;
hitinfo.pt = pNMItemActivate->ptAction;
int nItem = pListCtrl->HitTest(&hitinfo);
if (hitinfo.flags != LVHT_ONITEMICON)
return;
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
LV_ITEM* pItem = &(pDispInfo)->item;
if (pItem->iImage == 0)
pItem->iImage = 1;
else
pItem->iImage = 0;
pListCtrl->SetItem(pItem);
pListCtrl->UpdateWindow(); //this is wrong as nothing seems updated after all.
}
Given that the created imagelist is inserted into the pListCtrl already (in OnInitialUpdate method) and I set the output image index value in OnLvnGetdispinfo method.
(2) Instead of handling OnNMClick, I read somewhere people's advice that OnLvnItemchanged method could also be used. However in LPNMLISTVIEW struct, there is uNewState and uOldState variable members for which I don't know how to set up my tiny checked and unchecked icons as status images. Because I might have to do this
if (pNMLV->uChanged & LVIF_STATE)
{
switch (pNMLV->uNewState & LVIS_STATEIMAGEMASK)
{
case image1://do
case image2://do
}
}

Modifying column header names in Master-Detail grid in Devexpress

I have a Master-Detail set up with 2 grids. On the master grid, I have the ShowOnlyPredefinedDetails option set to false.
This means that I see a little + sign that allows me to expand the details of the detail grid (in the master grid). I would like to rename
some columns in that section as well as hide certain columns. I'm using VB.NET How do I go about this. See image.
You can accomplish this by using the grid control ViewRegistered event, from there you can modify the columns in that grid view that have columns within them that you want to modify, rename, or remove. Here is an example, I hope that it helps:
private void myGridControl_ViewRegistered(object sender, DevExpress.XtraGrid.ViewOperationEventArgs e)
{
if (e != null)
{
if (e.View != null)
{
//Inside of this statement you can adjust, add, and modify all of the columns inside of that grid that appears when you click on the +
(e.View as GridView).Columns["myHiddenColumn"].Visible = false;
(e.View as GridView).Columns.Add(new GridColumn() { Name = "AddColumn", Caption = "Name To Display", Visible = true, FieldName = "DataField"});
(e.View as GridView).Columns["DataField"].OptionsColumn.AllowEdit = false;
(e.View as GridView).Columns["DataField"].OptionsColumn.AllowFocus = false;
(e.View as GridView).Columns["DataField"].OptionsColumn.ReadOnly = true;
}
}
}
I think all you need to do is create a second grid view for your details. If you haven't already done this, do the following:
In your grid designer, click "Retrieve Details" if you have not already done so. This will cause the designer to recognize that you have a second level in your bound object:
Once you see the second layer, now you need a new grid view for it. Click on "Click here to change view" and select "Create a new view" and pick "GridView."
Now you will see both grid views from the designer, and clicking on one or the other will change the context of the menus to the left:
For example, if you have gridView2 selected, when you click on the "Layout" menu, it will show the current layout for your detail grid rather than the master grid. From here, you can remove or add columns as you see fit. Likewise, from the "Columns" menu you will see the new columns (you may have to add them to the view by dragging them over), and you can change the Caption property to change the text of the title.
I suggest you use the Data Annotation attributes with properties of your data-classes to declare how you data should be displayed in GridControl:
To skip column generation for the specific property you can mark this property with the <DisplayAttribute(AutoGenerateField := false)> declaration.
To prevent column from displaying you can mark this property with the <DisplayAttribute(Order := -1)> declaration. Later, user can show this column via Column Chooser UI.
To specify the column caption use the <DisplayAttribute(Name := "YOUR CAPTION")> declaration.
You can also control filtering/editing/formatting and validation capabilities.
Related Links:
Tutorial: Create and Manage Data in Code and Apply Data Annotation Attributes
Video Tutorial: Create and Manage Data in Code and Apply Data Annotation Attributes

Slow style binding in my windows store app

I have some buttons in my xaml which I want to bind the style dynamically based on some value. This all works great, but for maybe a second or two the buttons are not styled properly as my app is still loading. My application will load, but I have a list view that is waiting to receive some data from a web service. It seems as though the buttons won't be bound until the list view is bound.
Is there a way to set a "default" style on my buttons but still have my buttons bind at runtime without having to set all the properties for each button? Or why are my buttons taking so long to bind? Can I prioritize them?
Here is my button...
<Button x:Name="ButtonAll" Click="ButtonAll_Click" Style="{Binding State,Converter={StaticResource ButtonStateConverter},ConverterParameter=All}" Margin="0,0,50,0">All</Button>
Here is my converter code...
SampleState state = (SampleState)value;
SampleState param = new SampleState() { Code = (string)parameter, Name = (string) parameter };
if (state == param)
return App.Current.Resources["TextPrimaryButtonStyle"];
else
return App.Current.Resources["TextSecondaryButtonStyle"];

flex edit menu operations on multiple textareas

I have a grid in which one column is having itemrenderer as textarea. My application is menu controled. Now I want to perform edit operations on the textarea using menu items.
Like if I select some text from a textarea in the grid, then I select a menu item "Cut" then it should cut the selected text from the textarea. In this manner I would lie to perform all operations.
I am not getting how to get that the operation is to be performed on which textarea?
inside your menu item click handler, try:
var fcs:IFocusManagerComponent = focusManager.getFocus();
if(fcs is TextArea)
{
var txt:String = TextArea(fcs).text;
System.setClipboard(txt);
}