zoukankan      html  css  js  c++  java
  • datagrid column width in silverlight.

    The possible values for DataGridLenth are:

    • Auto: This auto-sizes the column or row to grow to the size of the largest header or cell.  It is effectively a combination of the other two auto-size modes.  You might notice as you scroll when a new larger cell is encountered that this value increases.  It will however not decrease once that item is scrolled out of view.
    • SizeToHeader: This auto-sizes the column or row the grow to the size of the header.  This will ignore the contents of the cells when determining its size and will not change unless the size of the header changes.
    • SizeToCells: This auto-sizes the column or row to grow to the size of the largest visible cell.  It will ignore the header cell in this calculation.  You might notice as you scroll when a new larger cell is encountered that this value increases.  It will however not decrease once that item is scrolled out of view.
    • Numeric: Unlike the others this is not an enum value, but rather simply a numeric value such as 100.  This mode will behave the same way that Beta 1 did, however setting it in code behind is slightly different.

    ===============================

    private void setColumnWidth()
            {
                double steadyWidth = 470;
                double variableWidth = dgView.Width - steadyWidth;

                if (dgView.Columns.Count >= 11)
                {
                    int[] adjustColumnIndex = new int[] { 0, 6, 7, 8 };
                    double[] ratio = new double[4] { 0.14742, 0.61503, 0.08983, 0.10596 };
                    for (int i = 0; i < adjustColumnIndex.Length; i++)
                    {
                        dgView.Columns[adjustColumnIndex[i]].Width = new DataGridLength(ratio[i] * variableWidth);
                    }
                }
            }

    ===================

            private void adjustColumnWidth()
            {
                double totalActualWidth = 0;
                foreach(var column in dgView.Columns)
                {
                    if (column.Header != null && column.Header.ToString().ToLower().Trim() == "reg. no.")
                    {
                        column.Width = new DataGridLength(70);
                      
                        column.Width = DataGridLength.SizeToCells;

                        dgView.UpdateLayout();
                     
                    }
                    else if (column.Header != null && column.Header.ToString().ToLower().Trim() == "location")
                    {
                        column.Width = new DataGridLength(70);

                        column.Width = DataGridLength.SizeToCells;

                        dgView.UpdateLayout();

                    }
                    totalActualWidth += column.ActualWidth;
                }
                double difWidth = dgView.Width - totalActualWidth - 20;
                foreach (var column in dgView.Columns)
                {
                    if (column.Header !=null && column.Header.ToString().ToLower().Trim() == "location" && column.ActualWidth >= -difWidth)
                    {
                        column.Width  = new DataGridLength(column.ActualWidth + difWidth);
                        //column.Width = DataGridLength.SizeToCells;
                        break;
        }
                }

                //auto height the height row.
                dgView.RowHeight = 10;
                Dispatcher.BeginInvoke(delegate
                {
                    dgView.RowHeight = double.NaN;
                });

            }

  • 相关阅读:
    [Effective JavaScript 笔记] 第7条:视字符串为16位的代码单元序列
    [翻译]CSS模块-未来的编码方式
    [Effective JavaScript 笔记] 第6条:了解分号插入的局限
    [Effective JavaScript 笔记] 第5条:避免对混合类型使用==运算符
    [Effective JavaScript 笔记] 第4条:原始类型优于封闭对象
    [翻译]理解CSS模块方法
    [翻译]纠正PostCSS的4大认识误区
    [翻译]Gulp.js简介
    [Effective JavaScript笔记]第3条:当心隐式的强制转换
    [翻译]在gulp构建工具中使用PostCSS
  • 原文地址:https://www.cnblogs.com/visi/p/1886640.html
Copyright © 2011-2022 走看看