Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » How can I set an image in GridCtrl cell ?
How can I set an image in GridCtrl cell ? [message #13461] |
Wed, 09 January 2008 20:14  |
jlfranks
Messages: 57 Registered: May 2007 Location: Houston, TX, USA
|
Member |
|
|
I have a GridCtrl that needs one column set to display one of
three icons from my .iml file.
The icon image needs to change based on external events.
1) How do I initialize the column so it can display icons?
2) How do I set and/or change the icon image?
--jlf
|
|
|
|
|
|
Re: How can I set an image in GridCtrl cell ? [message #59211 is a reply to message #13461] |
Sat, 26 November 2022 23:46   |
 |
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
If you want a view something like this:

One possibility is:
#include <GridCtrl/GridCtrl.h>
using namespace Upp;
#define IMAGEFILE "ImageGridCtrl/Icons.iml"
#define IMAGECLASS Images
#include <Draw/iml.h>
//from HomeBudget example
struct DispPM : GridDisplay
{
virtual void Paint(Draw &w, int x, int y, int cx, int cy, const Value &val, dword style,
Color &fg, Color &bg, Font &fnt, bool found, int fs, int fe)
{
if (val==0)
SetCenterImage(Images::one());
else if (val==1)
SetCenterImage(Images::two());
else if (val==2)
SetCenterImage(Images::three());
else
SetCenterImage(val);
GridDisplay::Paint(w, x, y, cx, cy, Value(""), style, fg, bg, fnt, found, fs, fe);
}
};
struct ImageGrid : TopWindow
{
GridCtrl gr;
ImageGrid() {
gr.AddColumn("Images").SetDisplay(Single<DispPM>());
for (int i = 0; i < 3; i++ )
{
gr.Add(i);
}
for (int i = 0; i < 10; i++ )
{
int r = Random(255);
int g = Random(255);
int b = Random(255);
Image img = CreateImage(Size(64,64), Color(r, g, b));
gr.Add(img);
}
Add(gr.SizePos());
};
~ImageGrid() {;};
};
GUI_APP_MAIN
{
ImageGrid().Title("ImageGrid").Run();
}
Another possibility would be something like this:
gr.AddColumn("RichText").Ctrls<RichTextView>();
with a possible mini Uword Editor to add images and/or links.
Btw, for some reasons, I couldn't get to work this case:
gr.AddColumn("ImageCtrl").Ctrls<ImageCtrl>();
which seems the most logical to use...
P.S. I see you need some help with answering questions on forums?..
P.P.S. Also, imho, there is a bug in GridCtrl::Clear(columns=true)
missing line:
aliases.Remove(1, aliases.GetCount() - 1); //TODO Report a BUG?
because if you clear columns and then add columns in the same GridCtrl again, it accumulates/duplicates aliases, messes up indexes and crashes...
the whole method should be at least like this:
void GridCtrl::Clear(bool columns)
{
doscroll = false;
anchor = Null;
UpdateCtrls(UC_HIDE | UC_CTRLS);
int nrows = columns ? 1 : fixed_rows;
items.Remove(nrows, items.GetCount() - nrows);
vitems.Remove(nrows, vitems.GetCount() - nrows);
total_rows = nrows;
fixed_rows = nrows;
if(columns)
{
hitems.Remove(1, hitems.GetCount() - 1);
items[0].Remove(1, items[0].GetCount() - 1);
rowbkp.Remove(1, rowbkp.GetCount() - 1);
edits.Remove(1, edits.GetCount() - 1);
sortOrder.Clear();
total_cols = 1;
total_width = 0;
total_height = 0;
firstCol = -1;
lastCol = -1;
fixed_cols = 1;
coluid = 0;
hcol = -1;
sortCol = -1;
genr_ctrls = 0;
firstVisCol = fixed_cols;
lastVisCol = total_cols - 1;
aliases.Remove(1, aliases.GetCount() - 1); //TODO Report a BUG?
}
else
{
total_height = fixed_height;
}
firstVisRow = fixed_rows;
lastVisRow = total_rows - 1;
focused_ctrl = NULL;
valid_cursor = false;
firstRow = -1;
lastRow = -1;
curpos.x = curpos.y = -1;
curid.x = curid.y = -1;
hrow = -1;
rowidx = -1;
rowuid = 0;
row_modified = 0;
UpdateSizes();
UpdateSb();
if(ready)
{
UpdateHolder();
oldpos.x = sbx;
oldpos.y = sby;
RebuildToolBar();
Refresh();
}
WhenEmpty();
WhenCursor();
doscroll = true;
}
|
|
|
Re: How can I set an image in GridCtrl cell ? [message #60046 is a reply to message #13461] |
Mon, 17 July 2023 00:56  |
ecapuano
Messages: 12 Registered: December 2021 Location: Mexico
|
Promising Member |
|
|
Did iyou make it to work with this user case?
gr.AddColumn("imageCtrl").Ctrls<imageCtrl>();
The other user case does not work very well when control is added into a different tab, is there something similar to VS where you just select a cell and then SetImage?
|
|
|
Goto Forum:
Current Time: Sun May 11 20:21:55 CEST 2025
Total time taken to generate the page: 0.04046 seconds
|