开发者

Get width of the clipped displayed column

I have a DataGrid in my project. It doesn't fit's the width of the form, so the scro开发者_高级运维llBar appears. The DataGrid, on it's initial state, displays a few columns and a part of the next column (which would appear after scrolling).

Is there any way, I can get the width of this, displaying part?


You should get the width of the parent object.

let's say the datagrid is in your application, then you should get the width of the stage.(stage.stageWidth)

If your datagrid is on a certain x location in your application (or any other parent object) then you should take the width of the parent object - the x value of your datagrid. (stage.stageWidth - dataGrid.x)


Ok, I had some time to dig more deeply in this problem. I've searched a few classes to see, how the Adobe was implementing those grid behavior (displaying columns partly). So, for those, who'll need to deal with this, the needed part is in DataGrid.as file, method configureScrollBars .. actually, this part of it:

// if the last column is visible and partially offscreen (but it isn't the only
        // column) then adjust the column count so we can scroll to see it
        if (collectionHasRows && rowCount > 0 && colCount > 1 && 
            listItems[0][colCount - 1].x + 
            visibleColumns[colCount - 1].width > (displayWidth - listContent.x + viewMetrics.left))
            colCount--;
        else if (colCount > 1 && !collectionHasRows)
        {
            // the slower computation requires adding up the previous columns
            var colX:int = 0;
            for (var i:int = 0; i < visibleColumns.length; i++)
            {
                colX += visibleColumns[i].width;
            }
            if (colX > (displayWidth - listContent.x + viewMetrics.left))
                colCount--;
        }

That's pretty much all code, that needed to catch and measure all those tricky divided cols in a grid :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜