Windows 移动应用程序 (Motorola MC55) 中 DataGrid 的列宽

Column width of a DataGrid in Windows Mobile Application (Motorola MC55)

我尝试在 C# 中为将 运行 在摩托罗拉 MC55 上 运行 的移动应用程序调整 DataGrid 的列宽。

我使用以下代码来执行此操作:

dataGrid1.TableStyles.Clear();
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = t.TableName;
foreach (DataColumn item in t.Columns)
{
    DataGridTextBoxColumn tbcName = new DataGridTextBoxColumn();
    tbcName.Width = 100;
    tbcName.MappingName = item.ColumnName;
    tbcName.HeaderText = item.ColumnName;
    tableStyle.GridColumnStyles.Add(tbcName);
 }
 dataGrid1.TableStyles.Add(tableStyle);

这 运行 在 Windows Mobile 6.5.3 上运行良好。专业模拟器。不幸的是,它不适用于摩托罗拉 MC55。

在 MC55 上,与我取消注释上面显示的代码时相比,列宽甚至更小。

你能帮我在 MC55 上运行吗?

我发现摩托罗拉MC55的屏幕尺寸与模拟器的屏幕尺寸不同。因此,我添加/更改了以下几行:

int screenWidth = Screen.PrimaryScreen.Bounds.Width;
int columnWidth = (screenWidth / 3) - (screenWidth / 16);
// divided by 3 because of 3 columns
// divided by 16 was a good fit to display the scrollbar
DataGridTextBoxColumn tbcName = new DataGridTextBoxColumn();
//tbcName.Width = 100;
tbcName.Width = columnWidth;

总之,我不明白为什么只有这些列出现问题。我总是习惯用绝对值来指定很多其他字段的大小。