Windows mobile 如何在WindowsMobile6中使用c#在datagrid中放置复选框?

Windows mobile 如何在WindowsMobile6中使用c#在datagrid中放置复选框?,windows-mobile,c#-3.0,Windows Mobile,C# 3.0,如何在WindowsMobile6中使用c#在datagrid中放置复选框 数据集dsAgent=table; DataTable=dsAgent.Tables[0] DataGridTableStyle tableStyle = new DataGridTableStyle(); tableStyle.MappingName = dataTable.TableName; GridColumnStylesCollecti

如何在WindowsMobile6中使用c#在datagrid中放置复选框

数据集dsAgent=table; DataTable=dsAgent.Tables[0]

            DataGridTableStyle tableStyle = new DataGridTableStyle();

            tableStyle.MappingName = dataTable.TableName;

            GridColumnStylesCollection columnStyles = tableStyle.GridColumnStyles;

            DataGridTextBoxColumn columnStyle = new DataGridTextBoxColumn();
            columnStyle.MappingName = "FirstName";
            columnStyle.HeaderText = "Name";
            columnStyle.Width = 80;
            columnStyles.Add(columnStyle);

            //columnStyle = new DataGridTextBoxColumn();
            //columnStyle.MappingName = "EmailAddress";
            //columnStyle.HeaderText = "EmailID";
            //columnStyle.Width = 150;
            //columnStyles.Add(columnStyle);

            columnStyle = new DataGridTextBoxColumn();
            columnStyle.MappingName = "WorkPhone";
            columnStyle.HeaderText = "PhoneNo";
            columnStyle.Width = 150;
            columnStyles.Add(columnStyle);


            GridTableStylesCollection tableStyles = DataGrid.TableStyles;
            tableStyles.Add(tableStyle);


            DataGrid.PreferredRowHeight = 16;
            DataGrid.RowHeadersVisible = false;
            DataGrid.DataSource = dataTable;

以下是Eric Hartwell(使用SO)的旧博客中的一些代码:


为了获得更好的复选框UI外观,而不是大十字架

private void DrawCheckBox(Graphics g, Rectangle bounds, CheckState state)
        {
            int size;
            int boxTop;

            size = bounds.Size.Height < bounds.Size.Width ? bounds.Size.Height : bounds.Size.Width;
            size = size > ((int)g.DpiX / 7) ? ((int)g.DpiX / 7) : size;

            boxTop = bounds.Y + (bounds.Height - size) / 2;
            size = 12; // 13, so I made it 12
            boxTop = boxTop - 1;
            using (Pen p = new Pen(this.Owner.ForeColor))
            {
                g.DrawRectangle(p, bounds.X, boxTop, size, size);
            }

            if (state != CheckState.Unchecked)
            {
                using (Pen p = new Pen(state == CheckState.Indeterminate ? SystemColors.GrayText : SystemColors.ControlText))
                {
                    p.Width = 2;
                    int offset = 2;
                    int edgeOffset = 2;
                    g.DrawLine(p, bounds.X + offset, boxTop + offset + 2, bounds.X + (size / 2) - edgeOffset, boxTop + (size / 2) + edgeOffset);
                    g.DrawLine(p, bounds.X + (size / 2) - edgeOffset, boxTop + (size / 2) + edgeOffset, bounds.X + size - offset, boxTop + offset);
                }
            }
        }
private void DrawCheckBox(图形g、矩形边界、CheckState)
{
整数大小;
int boxTop;
size=bounds.size.Height((int)g.DpiX/7)?((int)g.DpiX/7):大小;
boxTop=bounds.Y+(bounds.Height-size)/2;
size=12;//13,所以我把它改为12
boxTop=boxTop-1;
使用(Pen p=新笔(this.Owner.ForeColor))
{
g、 DrawRectangle(p,bounds.X,boxTop,size,size);
}
if(state!=CheckState.Unchecked)
{
使用(画笔p=新画笔(状态==检查状态.不确定?SystemColors.GrayText:SystemColors.ControlText))
{
p、 宽度=2;
整数偏移=2;
int edgeOffset=2;
g、 抽绳(p,bounds.X+偏移,boxTop+偏移+2,bounds.X+(尺寸/2)-边缘偏移,boxTop+(尺寸/2)+边缘偏移);
g、 抽绳(p,bounds.X+(尺寸/2)-边缘偏移,箱顶+(尺寸/2)+边缘偏移,bounds.X+尺寸-偏移,箱顶+偏移);
}
}
}

它有什么困难?这正好说明你在追求什么。如果有一些部分令人困惑或不清楚,请让我们知道,我们可以尝试帮助澄清。发布您尝试过的代码(上面的代码与复选框无关),也许我们可以帮助您。
private void DrawCheckBox(Graphics g, Rectangle bounds, CheckState state)
        {
            int size;
            int boxTop;

            size = bounds.Size.Height < bounds.Size.Width ? bounds.Size.Height : bounds.Size.Width;
            size = size > ((int)g.DpiX / 7) ? ((int)g.DpiX / 7) : size;

            boxTop = bounds.Y + (bounds.Height - size) / 2;
            size = 12; // 13, so I made it 12
            boxTop = boxTop - 1;
            using (Pen p = new Pen(this.Owner.ForeColor))
            {
                g.DrawRectangle(p, bounds.X, boxTop, size, size);
            }

            if (state != CheckState.Unchecked)
            {
                using (Pen p = new Pen(state == CheckState.Indeterminate ? SystemColors.GrayText : SystemColors.ControlText))
                {
                    p.Width = 2;
                    int offset = 2;
                    int edgeOffset = 2;
                    g.DrawLine(p, bounds.X + offset, boxTop + offset + 2, bounds.X + (size / 2) - edgeOffset, boxTop + (size / 2) + edgeOffset);
                    g.DrawLine(p, bounds.X + (size / 2) - edgeOffset, boxTop + (size / 2) + edgeOffset, bounds.X + size - offset, boxTop + offset);
                }
            }
        }