I have a ListBox with rows where each row consist of an "Image" and a "TextBlock". When I delete one row in the back with code likeļ¼
this.UserListBox.Items.RemoveAt(this.UserListBox.SelectedIndex);
There it throws an exception:
Operation not supported on read-only collection.
How can I delete row from the listbox?
I am writing a Windows phone 7 APP.
If you set ItemsSource on the ListBox, then Items is internally generated and readonly. In such case you need to delete the item from the supoplied item collection. If the collection implements INotifyCollectionChanged, then the collection changes are reflected in the listbox.
Instead of binding a List of items to your list box's itemsSource, you should instead use an ObservableCollection. This will fix the problem. The ObservabeCollection has a Remove method that you can use
UserListBox.Items.Remove(this.UserListBox.SelectedItem);
Related
I'm trying to make an array from a set of selectable cells in MS access.
Here's a section of my access DB:
I want the user to be able to select the cells with these numbers, dynamically (while code is running) and an array is created by selecting different cells. How can this be done in labview?
Thanks,
Use the correct code to work with the database (NI's DB toolkit, LabSQL, call the ADO.NET code directly, etc.) and get the data you want from the DB.
Place a listbox or multicolumn listbox on the front panel, change its selection mode to have 0 or more elements, so its data type becomes an array.
Use the Item Names property for the listbox to feed the data from the DB into the listbox.
The user will now need to select multiple items. This can be done by holding Ctrl, or you can call a Windows API function to press and release Ctrl on mouse enter/leave events, or you can use the Mouse Down event to figure out which row the user clicked on and use that to modify the value of the listbox (which is an array of the indices of the selected rows).
Once the user is done, you can read the value of the listbox (from its terminal) to get the indices, and use that to index the data from the Item Names property or from the original data you got from the DB.
Problem Statement :
We have a table of rows with unique GUID's and also Revit 3D Modal members associated with GUID's.
I am trying to highlight exact GUID Modal member On click of a checkbox of matching GUID from table row.
Please suggest on triggering point to highlight modal member dynamically.
Please find the attached screenshot for the reference.screenshot
There are a couple of ways of finding the object with your GUID. I would recommend using the Model.getExternalIdMapping method. It will generate a dictionary mapping internal IDs ("dbIDs") to external IDs (in this case, Revit GUIDs). You can then use this map in an "inverted" way, finding a dbID for a specific GUID.
Once you know the dbID of your object inside the viewer, you can use viewer.select, viewer.isolate, or similar methods to provide visual indication.
I have a referesh condition , after which the items in the drop down list of Access 2007 form gets altered.
For i = LBound(ddlRequestorNM) To UBound(ddlRequestorNM)
ddlRequestorNM.RemoveItem (i)
Next
The above code is erroring with Array out of index. I came to know that everytime , the item is deleted, the array index gets out of bounds. Some one pls help to delete all the items at once.
You should delete the items in reverse order:
For i = UBound(ddlRequestorNM) To LBound(ddlRequestorNM) Step -1
otherwise they are re-indexed every time one is deleted, eventually trying to refer to an item that doesn't exist.
For a standard ComboBox you can clear all items using ddlRequestorNM.RowSource = "".
You can also simply iterate the correct number of times, removing each time the 1st element :
For i = LBound(ddlRequestorNM) To UBound(ddlRequestorNM)
ddlRequestorNM.RemoveItem 0
Next
I'm creating a navigation form where some of the navigation buttons simply apply filters to the subform. Problem is right now each option is exclusive, i.e. I can select staff either by branch OR by job title. How can I make the options NOT exclusive so that I can apply multiple filters at once?
EDIT just to add. I have no knowledge of VBA so I'm trying to do this using the graphical interface and of macros. If it can't be done using these tools then fine, I'll find a different solution.
If you replace the .Filter property on a form (or subform) with a new value then the previous filter goes away. If you append a new clause onto an existing .Filter string, e.g. by changing...
[Branch]="Main"
...to...
[Branch]="Main" AND [Title]="Manager"
...then the new filter applies both criteria.
This solution requires a moderate amount of VBA (I can't think of a solution that wouldn't require it). Store the user's choices in module level variables and then apply your filters using a master ApplyFilters subroutine.
For example, give each checkbox an AfterUpdate event. This event will do 2 things:
Set the module level variable with the user's selection
Start the ApplyFilters sub
Since all the user's choices are now stored in module level variables, the ApplyFilters can see them all. It will:
Take all the module level variables and creates a master string (hint, if you need a Placeholder, use 1=1)
Apply that string as your subform's filter.
Other notes:
Accessing your subform's controls from the main form is simple. To change your subform's filter to the string NewFilter, try:
Forms!MyMainFormsName!MySubFormsName.Filter=NewFilter
I used a temporary array to populate a ListCollectionView. Later, I have a screen that displays a DataGrid using the ListCollectionView as a dataProvider. The user can delete a row in the DataGrid by selecting the row then clicking a Delete button.
How can I access the original source that ListCollectionView uses, and delete the item from there?
After I do that, will the item also be deleted from the ListCollectionView automagically, and no longer be shown in the DataGrid (or does something need to be refreshed)?
UPDATE 1
Does the following sound like I'm on the right track? (I want to remove it from the source (is that the ".list"?) of the ListCollectionView, not just from ListCollectionView.)
[Bindable] private var _myLCV:ListCollectionView=new ListCollectionView(new ArrayList());
...
var obj:Object = _myLCV.getItemAt(myGrid.grid.selectedIndex); // get item user selected
_myLCV.list.removeItemAt( _myLCV.list.getItemIndex(obj) ); // delete item from source
UPDATE 2
I'm not sure why (I'm using SDK 4.5.1A), but I seem to need to add the following line of code to the above code in UPDATE 1, for the DataGrid to reliably update and show the deleted row:
_myLCV.refresh();
My impulse is to recommend deleting the item from the ListCollectionView using removeItemAt.
If you truly want to access the source instead of dealing with the collection, then it depends what type of ListCollectionView you're using.
If you're using an ArrayCollection you can access the source using the source property.
IF you're using an XMLListCollection, you can access the source using the source property.
There isn't an inherent source property in the ListCollectionView, but the List property may suffice.
In any case, removing an item from the ListCollectionView or the ListCollectionView's source should automatically update the DataGrid. IF not, you can call the refresh() method on the collection.
Spark DataGrid, like other list base controls such as List or even DataGroup, would observe change events from its dataProvider. The change events may include item removal, update, sort and insertion. This provides the convenience of updating the control by just updating its underlying data.
That said, if your intent is to "refresh" the datagrid to stay up to date with the LIstCollectionView, by modifying the array and then refresh would rather be unnecessary.