display images in datagrid with Compact Framework

走远了吗. 提交于 2020-01-01 06:55:35

问题


is it possible to display an image in a datagrid cell? i'm currently working with compact framework 3.5.

any tips on that?


回答1:


Like the other posters have commented, you're required to roll your own. Luckily, this isn't too difficult.

In my application, I needed a way to draw a 16x16 icon in a particular column. I created a new class that inherits from DataGridColumnStyle, which makes it easy to apply to a DataGrid via a DataGridTableStyle object.

class DataGridIconColumn : DataGridColumnStyle {

public Icon ColumnIcon {
    get;
    set;
}

protected override void Paint( Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight ) {

    // Fill in background color
    g.FillRectangle( backBrush, bounds );

    // Draw the appropriate icon
    if (this.ColumnIcon != null) {
        g.DrawIcon( this.ColumnIcon, bounds.X, bounds.Y );
    }
  }
}

You can see that I defined the public property ColumnIcon so I can specify the icon I need to display outside of this class.

Now, to actually use it on a DataGrid, you'd have a snippet like:

DataGridTableStyle ts = new DataGridTableStyle();

DataGridIconColumn dgic = new DataGridIconColumn();
dgic.ColumnIcon = Properties.Resources.MyIcon;
dgic.MappingName = "<your_column_name>";
dgic.HeaderText = "<your_column_header>";

ts.GridColumnStyles.Add(dgic);

this.myDataGrid.TableStyles.Add( ts );

That's a pretty simple example for applying the DataGridTableStyle -- I actually do a lot of further customization on the rest of my DataGrid columns. But it should get you started on what you want to do.




回答2:


The only way that I know how to do this would be like the trick for rendering textboxes in the grid by using a trick to paint some images over the grid.

One of the CF team posted something about customising the grid on their site.




回答3:


It's the same process as doing multiline rows, changing row colors, making the text right-to-left, or highlighting a row: you have to custom draw.




回答4:


If you are able to use a third-party solution, have a look at Resco SmartGrid.




回答5:


http://www.cf-technologies.net/compactgrid.php. You can use cell's CustomDraw event..



来源:https://stackoverflow.com/questions/969937/display-images-in-datagrid-with-compact-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!