简体   繁体   中英

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

I try to adjust the column width of a DataGrid in C# for a Windows Mobile application that will run on a Motorola MC55.

I use the following code to do this:

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);

This is running fine on the Windows Mobile 6.5.3. Professional Emulator. Unfortunately it is not working on the Motorola MC55.

On the MC55 the column width is even smaller compared to when I uncomment the code shown above.

Can you please help me to get this working on the MC55?

I identified that the screen size of the Motorola MC55 was different from the screen size of the emulator. I therefore added / changed the following lines:

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;

Anyhow, I do not understand why the problem appears only for these columns. I always used to specify the size of lots of other fields with absolute values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM