View Full Version : Remove a selected row in a dataGrid??
chrishosch
05-03-2004, 01:23 PM
I'm using the dataGrid to display information that the user inputs. I was able to insert the data into the grid using the addItem() method and it's working wonderfully. However, I would like to add an option to remove items from the dataGrid but there is no removeItem() method. Ideally I'd like the user to be able to select a row of data and hit a remove button to delete that row. I know I can make the rows selectable and maybe use the cell focus in some way.
Has anyone done this? Why would there be an addItem() but no removeItem() method? Is there a way to remove a selected row from a dataGrid?
Any input is greatly appreciated.
Thanks,
Chris
annexion
05-03-2004, 02:12 PM
dgInstance.dataProvider.removeItemAt(dgInstance.se lectedIndex)
That might work. If it doesn't it's because the selectedIndex may not be anything if not fired through an event. In that case use the datagrid change handler to grab the index and set a variable with it. Then use your button, or whatever it is, to remove the item at that specific index.
chrishosch
05-03-2004, 03:26 PM
Hey, that worked! Thanks annexion! Why isn't that method published in the help? I've downloaded the most recent help but it's not there.
chrishosch
05-03-2004, 04:41 PM
On a related note, I'm now trying to add a "Clear All" button by using a for loop that looks at the length of an array and uses the removeItemAt() method.
Here's my code:
for (i=0; i < myArray.length; i++) {
trace("i = " + i);
myDataGrid.removeItemAt(i);
}
myArray.splice(0, myArray.length);
My problem is that it only removes every other item in my dataGrid; as though the code is only executing on an even increment or something. But, I know my for loop is working as my trace displays the correct numbers. Any ideas? Or is there a simpler way to remove all the items in a dataGrid?
Chris
annexion
05-03-2004, 09:02 PM
dataGrid.dataProvider.removeAll();
chrishosch
05-04-2004, 10:08 AM
So simple, yet so elusive...
Thanks.
annexion
05-05-2004, 09:37 AM
Check out the following in your help docs. Using the dataProvider of a grid, without actually having to set one beforehand, gives you all those functions that you're looking for.
Using Components > Components Dictionary > DataProvider API
darth
10-16-2008, 03:33 PM
anyhow, if DataGrid class has selectedIndex property it should be documented
>:(
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.