On a toolbar manager button event I would like to process an action on each selected row of a specific band from an UltraGrid.
I have read many postings on this form but none of them explain clearly how to capture the selected rows of a specific band in the grid.
The grid band is [1] with the name "ttReceiptLines". Would prefer using names over index numbers (more clear for reading source which data object you work on).
What kind of object do I need to capture the selected rows? Can this be a RowsCollection?
How can I process each item of the collection to read info from them?
Need to identify the line number, the quantity and other line info to process and forward them to an other Receipt List.
Kind regards,
Peter Wokke
Hi Peter,
Thank you for posting in our forums.
You can get the selected rows from a specific band using the following line:
var selectedRows = ultraGrid1.Selected.Rows.OfType<UltraGridRow>().Where(r => r.Band.Key == "ttReceiptLines").ToList();
This will return you a collection of type List<UltraGridRow> and you can use the cells collection of each row to get the information you need when you are generating your Receipt List.
Please let me know if you have any additional questions.
Dimitar,
Thank you kindly for your replay.
Do not much understand the code in your example.
I develop in Progress and notation is different.
The dot separations I have to replace with :.
And example to get Info from the activeRow in Progress:
define variable iReceiptID as integer no-undo. define variable cStatus as character no-undo. define variable iPurposeID as integer no-undo. define variable clsSelectedRows as RowsCollection no-undo. define variable clsCurrentRow as UltraGridRow no-undo. define variable clsCells as CellsCollection no-undo. define variable clsCell as UltraGridCell no-undo. /* get to the ActiveRow ReceiptID */ if (ultraGridReceipt:ActiveRow <> ?) then do: clsCurrentRow = ultraGridReceipt:ActiveRow. clsCells = clsCurrentRow:Cells. clsCell = clsCells:item["ReceiptID"]. iReceiptID = integer(clsCell:Text). clsCell = clsCells:item["PurposeID"]. iPurposeID = integer(clsCell:Text). clsCell = clsCells:item["StatusCode"]. cStatus = clsCell:text. end.
This I do not understand at all:
OfType<UltraGridRow>().Where(r => r.Band.Key == "ttReceiptLines").ToList()
Is this a kind of casting?
Hope you can help on this?
Peter
Thank you for the reply.
I am not familiar with Progress, but I will try to give you explanation what the code does and hopefully this will help you translate the code to Progress. The OfType<UltraGridRow>().Where(r => r.Band.Key == "ttReceiptLines").ToList() are LINQ statements. What they basically do is to cast the collection to IEnumerable<UltraGridRow> (the OfType part), then filter the rows which are part of the "ttReceiptLines" Band (the Where part) and then return a List<UltraGridRow> object (the toList part).
You can achieve the same result by iterating the Selected.Rows collection and then checking if the row’s Band.Key is the desired one. The following code achieves this in C#:
SelectedRowsCollection selectedRowsCollection = ultraGrid1.Selected.Rows; foreach (UltraGridRow selectedRow in selectedRowsCollection) { if (selectedRow.Band.Key == "ttReceiptLines") { // Use these rows to populate the Receipt List } }
I am glad that your issue is resolved. Please let me know if you have any additional questions.
Thank you for using Infragistics Components.
Hello Dimitar,
I have found this mistake and use an object which is a type of SelectedRowsCollection now.
In Progress language I forward this example for you.
Kind regards and thanks,
Peter.
define variable clsSelectedRows as SelectedRowsCollection no-undo.
define variable clsCurrentRow as UltraGridRow no-undo.
define variable clsCells as CellsCollection no-undo.
define variable clsCell as UltraGridCell no-undo.
define variable iOrderNumber as integer no-undo.
define variable iOrderLine as integer no-undo.
define variable iPackings as integer no-undo.
clsSelectedRows = ultraGridShipment:Selected:Rows.
do iIndex = 0 to clsSelectedRows:count - 1 :
clsCurrentRow = clsSelectedRows[iIndex].
if clsCurrentRow:Band:Key = "ttReceiptLines" then do:
clsCells = clsCurrentRow:Cells.
clsCell = clsCells:item["OrderNumber"].
iOrderNumber = integer(clsCell:Text).
clsCell = clsCells:item["LineNumber"].
iOrderLine = integer(clsCell:Text).
clsCell = clsCells:item["Packings"].
iPackings = integer(clsCell:Text).
message "Receipt line is: " iOrderNumber iOrderLine
skip "Number of packings is :" iPackings
view-as alert-box.
end.
I
The Selected.Rows property returns SelectedRowsCollection, not RowsCollection. This may be the reason for the compiler error. This can be iterated with both for and foreach loops in C#. So if you assign the Selected.Rows collection to a variable of type SelectedRowsCollection you should be able to iterate it and find which rows belong to the band you are looking for.
Hi Dimitar,
I have tried this:
define variable clsSelectedRows as RowsCollection no-undo.
/* to define a class object RowsCollection and assign the selected rows of the grid to it by. */
clsSelectedRows = ultraGridReceipt:selected:Rows.
This gives the compile warning of incompatible data type in expression or assignment.
It looks like I cannot assign the Selected:Rows of a grid like this to a RowCollection.
Should I assign it as another kind of UltraGrid property then a RowCollection?
In Progress for each works on datasets not on grids.
You can loop through (indexed) items of properties of those objects.
Which item is the index item I should use in this case?
Hope you can help.