DataGrid宽度 [英] DataGrid Width

查看:70
本文介绍了DataGrid宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我已经调整了DataGrid中的列的大小,我想设置

DataGrid的宽度以适应列。由于左侧的网格和灰色行选择列,只是将列宽总和太短了




我有列的宽度。我还需要包含哪些其他值?

的DataGrid宽度?


Thanx,

Bill

Hi y''all,

I have resized the columns in a DataGrid and I want to set the width of the
DataGrid to fit the columns. Just summing the column widths is too short
due to the grid and gray row selection column on the left.

I have the widths of the columns. What other values do I need to include in
the DataGrid width?

Thanx,
Bill

推荐答案

您是在谈论ASP.NET数据网格还是Windows数据网格?


" web1110" <我们*** @ comcast.net>在消息中写道

新闻:N _ ******************** @ comcast.com ...
Are you talking about an ASP.NET datagrid or a Windows Datagrid?

"web1110" <we***@comcast.net> wrote in message
news:N_********************@comcast.com...
你好你好了,我已经调整了DataGrid中的列的大小,我想设置
DataGrid的宽度以适应列。由于左侧的网格和灰色行选择列,只是将列宽总和太短了。

我有列的宽度。我需要在DataGrid的宽度中包含
还有哪些其他值?

Thanx,
Bill
Hi y''all,

I have resized the columns in a DataGrid and I want to set the width of
the
DataGrid to fit the columns. Just summing the column widths is too short
due to the grid and gray row selection column on the left.

I have the widths of the columns. What other values do I need to include
in
the DataGrid width?

Thanx,
Bill



一个Windows DataGrid。
A Windows DataGrid.


由于DataGrid绘制自己的边框,而垂直滚动条是一个

位于客户区顶部的子控件,你需要考虑

BorderStyle,RowHeaderWidth,列宽和垂直滚动条

宽度(如果有的话) )。要检索列宽,下面的代码假定DataGrid使用自定义DataGridTableStyle

。如果这不是

的情况,那么你可能需要对源进行一些调整。


使用System.Reflection;

private void AutoSizeDataGridWidth(DataGrid grid)

{

int width = 0;


//计算占用边框空间。

开关(grid.BorderStyle)

{

case BorderStyle.None:

{

//什么都不做。

休息;

}

case BorderStyle.FixedSingle:

{

宽度+ = 4;

休息;

}

case BorderStyle.Fixed3D:

{

宽度+ =(SystemInformation.Border3DSize.Width * 2);

休息;

}

}


//计算占用的行标题空间。

if(grid.TableStyles.Count> 0)

{

if(grid.TableStyles [0] .RowHeadersVisible)

{

width + = grid.RowHeaderWidth;

}

}

else if(grid.RowHeadersVi sible)

{

width + = grid.RowHeaderWidth;

}


//计算占用列空间。

if(grid.TableStyles.Count> 0)

{

foreach(

grid.TableStyles [0] .GridColumnStyles中的DataGridColumnStyle列)

{

宽度+ = column.Width;

}

}


//计算占用垂直滚动条空间。

PropertyInfo propInfo = grid.GetType()。GetProperty(" VertScrollBar",

BindingFlags.Instance | BindingFlags.NonPublic);

if(propInfo!= null)

{

ScrollBar propValue = propInfo.GetValue(grid,null)as ScrollBar;

if(b) propValue!= null)

{

if(propValue.Visible)

{

width + = propValue。宽度;

}

}

}


grid.Width = width;

}


-

Tim Wilson

..Net Compact Framework MVP


" web1110" <我们*** @ comcast.net>在消息中写道

新闻:N _ ******************** @ comcast.com ...
Since the DataGrid draws its own borders and the vertical scroll bar is a
child control that sits on top of the client area, you''ll need to consider
the BorderStyle, RowHeaderWidth, column widths, and vertical scroll bar
width (if present). To retrieve the column widths, the code below assumes
that the DataGrid is using a custom DataGridTableStyle. If this is not the
case then you may need to make some tweaks to the source.

using System.Reflection;

private void AutoSizeDataGridWidth(DataGrid grid)
{
int width = 0;

// Calculate occupied border space.
switch (grid.BorderStyle)
{
case BorderStyle.None:
{
// Do nothing.
break;
}
case BorderStyle.FixedSingle:
{
width += 4;
break;
}
case BorderStyle.Fixed3D:
{
width += (SystemInformation.Border3DSize.Width * 2);
break;
}
}

// Calculate occupied row header space.
if (grid.TableStyles.Count > 0)
{
if (grid.TableStyles[0].RowHeadersVisible)
{
width += grid.RowHeaderWidth;
}
}
else if (grid.RowHeadersVisible)
{
width += grid.RowHeaderWidth;
}

// Calculate occupied column space.
if (grid.TableStyles.Count > 0)
{
foreach (DataGridColumnStyle column in
grid.TableStyles[0].GridColumnStyles)
{
width += column.Width;
}
}

// Calculate occupied vertical scrollbar space.
PropertyInfo propInfo = grid.GetType().GetProperty("VertScrollBar",
BindingFlags.Instance | BindingFlags.NonPublic);
if (propInfo != null)
{
ScrollBar propValue = propInfo.GetValue(grid, null) as ScrollBar;
if (propValue != null)
{
if (propValue.Visible)
{
width += propValue.Width;
}
}
}

grid.Width = width;
}

--
Tim Wilson
..Net Compact Framework MVP

"web1110" <we***@comcast.net> wrote in message
news:N_********************@comcast.com...
你好你好了,我已经调整了DataGrid中的列的大小,我想将
的宽度设置为DataGrid以适应列。由于左侧的网格和灰色行选择列,只是将列宽总和太短了。

我有列的宽度。我还需要在DataGrid宽度中包含
还有哪些其他值?

比尔,
Hi y''all,

I have resized the columns in a DataGrid and I want to set the width of the DataGrid to fit the columns. Just summing the column widths is too short
due to the grid and gray row selection column on the left.

I have the widths of the columns. What other values do I need to include in the DataGrid width?

Thanx,
Bill



这篇关于DataGrid宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆