Domanda

I have a gridview with a bunch of groups in it. I also have up/down buttons which move the datarows inside of the groups up/down. If the datarow is the last row in the group, I don't want the row to do anything when the user presses the "down" button. How can I check to see if the data row is the last row in the group?

È stato utile?

Soluzione

You can try this

int rowHandle = view.FocusedRowHandle;
int groupRow = view.GetParentRowHandle(rowHandle);
var childRows = GetChildRowsHandles(view, groupRow);
if (childRows.Count > 0 && childRows.Last() == rowHandle)
{ 
    //selected row is the last datarow of its GroupRow
}

public List<int> GetChildRowsHandles(GridView view, int groupRowHandle)
    {
        List<int> childRows = new List<int>();  

        if (!view.IsGroupRow(groupRowHandle))
        {
            return childRows;
        }

        int childCount = view.GetChildRowCount(groupRowHandle);
        for (int i = 0; i < childCount; i++)
        {
            int childHandle = view.GetChildRowHandle(groupRowHandle, i);
            if (view.IsDataRow(childHandle))
            {
                if (!childRows.Contains(childHandle))
                    childRows.Add(childHandle);
            }
        }

        return childRows;
    }

Note: I haven't tested the code. try it out.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top