Flex/AS3: removing item from ListCollectionView - actionscript-3

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.

Related

Labview - How to select data from MS access table as input array?

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.

How to remove all the items in a dropdownList in Access 2007?

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

MySQL result to array VB.NET

I am creating a program in VB.NET which uses an online MySQL database to retrieve certain data. I have now succeeded in connecting and getting some basic stuff out of it. Now, what I want to do is that when an user presses a button it has to update the list. What happens is that the stuff that is already in the database also gets resent and so the list just doubles himself, although it adds the new database value.
How can I make sure that it only adds new values to the list, instead of adding all values from the list again? I have read that you can use the Preserve keyword with arrays, though this isn't an array and neither have I figured out how to convert my data into an array.
Private Sub generateList()
DB.writeQuery("SELECT snacks.ID, snacks.naam, snacks.baktijd FROM snacks")
While DB.DR.Read
ListBox1.Items.Add(DB.DR.Item("naam"))
End While
DB.closeConnection()
End Sub
This is the piece of code I use to generate the list, I reuse this code to refresh the list. As you can see, it uses my own written MySQL class. I know it makes an connection so there is nothing wrong with that.
Any help would be appreciated.
What you will want to do is to clear the ListBox before you reload the list. You can do this like so:
ListBox1.Items.Clear()
Then when you reload the list, the items will not be duplicated.
Looks like you need to clear your listbox before adding the items.
ListBox1.Items.Clear()
Try this my friend:
If Not listBox1.Items.Contains(DB.DR.Item("naam")) Then
ListBox1.Items.Add(DB.DR.Item("naam"))
else
'this item already exists.
end if

Operation not supported on read-only collection

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);

ExtJS grid - how to focus on added row?

I have a grid(gridpanel) and data in it which I read from json query. After I added new bussines object(row) - I send him in json format to server, write to DB, and reload all grid. How I can focus on currently added row(b/o) after that? I will be very cool if I return added id at the json answer and grid take it and focus on row with added id.
Thx.
How is your data being added (append-mode or not?). You can do grid_panel.getView().focusRow(row) on the length of the data array in the store, which will focus on the "last" row that was inserted. Also, you could hook into the rowsinserted event of GridView, and focusRow on the lastRow parameter that's passed in there.