I have one grid that has two bands.
How to determine which band is being selected or band row being selected
Basically, I want to write some logic that saids
If( Band[1] Is active or any row is selected)
{"do nothing, at the moment I careless about band[1], it there for visual at the moment."}
else if (Band[0] is selected or row is selected)
{"get data"}
Hey,
With the UltraGrid.Selected you can retrieve what is selected.
Example:retrieve the band index of the first selected row: UltraGrid.Selected.Rows(0).Band.Index retrieve the band index of the first selected cell: UltraGrid.Selected.Cells(0).Band.Index
If no cell, row or column is selected, I'm not sure if any band is selected and as such I don't think you'll be able to retrieve that.
Kind regards,
Michael
So are you telling me if 5 rows of Band[0] and each band has relative Band[1]
if I click on any of the 5 Band[1] rows it would jump in the else statement below?
if
(ultraGrid1.Rows[0].Band.Index == 0)
{
do something
}
else
do nothing
No, that is not correct.
ultraGrid1.Rows is the root-level rows collection of the grid. If you specify ultraGrid1.Rows[0] or use any number inside the brackets, you will always get a row in Band 0.
The code Michael posted above is using the Selected property on the grid to get the Selected rows, not the root rows.
ultraGrid1.Selected.Rows[0]
I suspect you don't care about selection, you are probably more concerned with the active row.
ultraGrid1.ActiveRow
Whatever row you are working with doesn't really matter. Once you get whatever row you care about, the row has a Band property on it, so you can then examine the Key or Index of the band to determine which band that row belongs to.
Thanks you are the greatest. One more thing that I caught
I am doing this below. Thanks.
if (ultraGrid1.ActiveRow.Band.Index != 1)
Question . If I click on Band[1]. How to get the Band[1] related values from Band[0]. If you know what I mean. Band[1] is related from Band[0].
QuicK Example:
Color ID : Color:
-- Band[0] Row: 1 Red
Color ID : Color Notes:
----------Band[1] Row: 1 I love Red
So if I click on Band[1] Row Color ID 1, How do I get the Band[0] Row 1 Information?
Not for sure uf you understand what Im trying to accomplish.
A Band represents the entire band - that is, all of the rows at a particular level. So a Band doesn't have a parent row. The band represents all of the child rows under all parent rows.
To get a parent row, you need a child row. The row has a ParentRow property on it.
For parent row I am using logic below
parentRowInfo = (DataRowView
)ultraGrid1.ActiveRow.ParentRow.ListObject;
For the child row i am using logic below
DataRowView childRowInfo = (DataRowView)ultraGrid1.ActiveRow.ChildBands.FirstRow.ListObject;