سؤال

In Windows Application, There is one property AutoSizeColumnsMode for DataGrid, which determines auto size modes for the visible columns.

I am developing Windows Mobile Application using .Net Framework 3.5 , there is no similar property for DataGrid.

How similar functionality can be implemented?

لا يوجد حل صحيح

نصائح أخرى

I haven't tried dynamically changing the width of the column when cell values change but I use this method to set the column width from the header. You may want to add extra padding to get the best results

    private static int MeasureTextWidth(Control c, string text)
    {
        if (c == null)
        { return -1; }
        using (Graphics g = c.CreateGraphics())
        {
            return (int)Math.Ceiling(g.MeasureString(text, c.Font).Width);
        }
    }

Edit: extra note I have tried implementing a auto width feature for columns by overriding the Width property on the column with my own logic. Unfortunately it seems that DataGridColumn doesn't use the Width property to get its width. Just incase you were thinking about going that route.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top