You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can I add Multiple icons (images) in a single Datagrid view Cell - all with separate click Events #1073
We need to add a "Action Bar" to each row of a data grid view. So our idea was to add a bunch of icons in Column 1 after the data is retrieved to allow the user to take different actions on a particular row - like bookmark, edit, forward info, etc.
I didn't like the look of individual cells for each icon as the header looks strange and they show the bars between them.
Is it possible - and have separate click events so we know what they clicked and what row they clicked it on?
Yes, look at the Role property of the click event. If you add the role attribute to your HTML it will come back to the server.
Your cell can be something like this:
<img role='edit' src='....'/><img role='view' src='....'/>, etc.
To line them up you can add a css class name or a style attribute changing the display to inline-block. You can add a css file to Default.html. When you click on the img you'll get e CellClick event (or CellDoubleClick, CellMouseDown, etc...) with the Role property set to the value from the HTML.
We use this internally to detect clicks on the checkbox inside a checkbox cell and on the open/close button for hierarchical rows.
It's better to use the html approach, otherwise you'd be creating hundreds of controls. The "control in the cell" feature is meant to be used to create super cool grid panels.
To add tooltips simply add the title="tooltip text" attribute to the tag.
Can you give me a sample with the code ? When I tried this all i get is the HTML in the datagrid cell – it does not render the icons.
I am retieving data from the database, then adding a column to the data table and assigning the html from your post:
DataColumn dc = new DataColumn(“Actions”);
dc.DataType = typeof(string);
dc.DefaultValue = “”; (sorry – HTML does not show but its what you have above.)
ldt_Data.Columns.Add(dc);
You have to set col.AllowHtml = true; Anytime you want to use HTML in Wisej controls the AllowHtml property have to be true, otherwise the html tags are not encoded since normal text may have the greater than and lower than operators as part of the text.
Yes, that fixed it.
Now – one more question – can I use the built in “icons” the ones in the font packages instead of having to put actual images in the folder ?
Yes for the icon packages, not for the theme icons. For the icon packages use the same url that comes with the static class: i.e. Wisej.Ext.MaterialDesign.Icons…. You can either use the full path resource.wx/Wisej.Ext.MaterialDesign/back-arrow.svg or the short path resource.wx/back-arrow.svg. In the second case, Wisej will return the first back-arrow.svg resource that it can find in the resource assemblies.
Tried it with ElegantIcons. Compiled the extension project and put the DLL in my project folder, added a reference to it.
Using img role=’test’ src=’ resource.wx/Wisej.Ext.EleganIcons/archive-box.svg’ – i just get the “X” in place of the image in the grid. The click even does work however. Just trying to sort out the graphic issue,
You have the wrong name EleganIcons instead of ElegantIcons. The “t” is missing. Also, since the images are svg images in an img element you can’t change the color. Wisej changes it by loading the svg xml document and changing the fill. Another option you have if you want to change the color is to use a real font icon set, which would work exactly as in any HTML page. Or you can change the color in the svg itself and save it back.
I figured out what is going on, see attached screen shot. It appears that even with the style in your example added to default html - the size of the "font" icon is very large. When i stretched the cell wider - you can see how large it is. How can I set the size of the font ? Is this done in the Style as well ?
Sorry - coming from VWG we are not used to mixing HTML and C# to do this -although I see how powerful it is !
SVG icons need the size because they are vectorial and usually designed on a large canvas, like 800x800. Setting the size on the img element directly or through css must work, it's part of the browser. I also tried IE11 and FireFox.
I got it to work as well early this AM. After I edited default.html again and set it to 32×32 it worked. Then I backed it down to 16×16 again and now it works. Strange, it’s almost as if the style was not being used in default.html until i edited it again.
Okay – after it worked, i added in another icon to the list in the html. Ran it again – icons don’t show up After some testing I figured out that if I edit Default HTML again and just change the size even just 2 px to 18px and run – they show up. I edit and add another icon to html – same issue. I put the px back to 18px, run – they show up. Put it back to 16px and they still show up.
If you want to do a screen share I can set one up so you can see it. Strange behavior.
It would be cool if in the HTML we could specify the fill color and when the resource is returned it can be the color specified. I like to limit the amount of free floating images on the deployment hard drive as much as possible. Maybe use the standard HTML # color tag ?
The HTML color tag doesn’t work on svg images. The fill style only works on svg elements. Wisej performs the color change on the client but it kicks in only for Wisej widgets and during the image preloading. Wisej supports a ?color=[color] parameter already, but it can only be processed by Wisej widgets since we have to way of changing the way a src attribute in img works. The color could change could be processed on the server instead of the client but it’s kind of overkill. Another way to achieve this is to use a font icon set and use the css names and unicode entitired defined by the font, see font awesome for example. This is the main reason why when working just with HTML the svg icons had to be converted to fonts.
But once i set the style in default.html – why would i have to make an edit to it for the HTML in the datagrid to work ? I should only have to set the style one time and forget it right ?
Try to clear the cache or another browser or add a parameter to Default.htm?v=1. Looks like the browser is still retrieving the first Default.html without the style.
No – what happens is – its working – then after I edit the html in the datagrid cell to add another icon and I run it it stops showing the icons. It initially does until I edit the cell HTML again. Then it stops. The only way to get it to work again is to go and make a change to default.html – then it will show the icons again in the datagrid cell. Even if i just edit they style to 18px save it , then edit it again back to 16px, save it – then run. Then the Icons show up in the datagrid cell.
Tried that by adding img role=’test’ src=’resource.wx/Wisej.Ext.ElegantIcons/arrow-up.svg’ class=’cell-image’. It’s just html, if it doesn’t work there is a problem with the browser, cache, etc. Verify using F12 with Chrome, select Elements, click the button (top left) “Select an element…” and inspect the HTML. Select the img element and you should see on the right, under Styles and Computed, the effective style. That show show exactly what’s wrong.
Activity
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-09-05 00:34:03 UTC
Yes, look at the Role property of the click event. If you add the role attribute to your HTML it will come back to the server.
Your cell can be something like this:
To line them up you can add a css class name or a style attribute changing the display to inline-block. You can add a css file to Default.html. When you click on the img you'll get e CellClick event (or CellDoubleClick, CellMouseDown, etc...) with the Role property set to the value from the HTML.
We use this internally to detect clicks on the checkbox inside a checkbox cell and on the open/close button for hierarchical rows.
I tried a small sample, see below:
Used this in Default.html
This in the cell:
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-05 00:42:09 UTC
Awesome - thanks for the quick response! I'll give it a try.
itg-assistant commentedon Jun 12, 2026
Frank (ITG) answered 2017-09-05 00:51:07 UTC
Hi Edmond,
do you think about something like this ?
It can be achieved quite easily by using a panel with some buttons that are used as Control in each cell.
Please let me know if you need some sample code to get started.
Best regards
Frank
itg-assistant commentedon Jun 12, 2026
Frank (ITG) answered 2017-09-05 00:54:28 UTC
Luca was faster :-) But now you have a second approach that could be used. Regards, Frank
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-05 14:08:41 UTC
Any advantage/disadvantage to either approach ?
The datagrid may have a few thousand records (15k, 20k ?) at times.
Also - it would be nice to have tool tips when the user hovers over the icons - can this be done as well ?
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-09-05 19:33:05 UTC
It's better to use the html approach, otherwise you'd be creating hundreds of controls. The "control in the cell" feature is meant to be used to create super cool grid panels.
To add tooltips simply add the title="tooltip text" attribute to the
tag.
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-05 19:43:20 UTC
Got it - makes sense to just have the HTML because there can be thousands of records.
Will the Cell Click event also give me the current row that was clicked ?
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-06 16:40:31 UTC
Can you give me a sample with the code ? When I tried this all i get is the HTML in the datagrid cell – it does not render the icons.
I am retieving data from the database, then adding a column to the data table and assigning the html from your post:
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-09-06 17:46:33 UTC
You have to set col.AllowHtml = true; Anytime you want to use HTML in Wisej controls the AllowHtml property have to be true, otherwise the html tags are not encoded since normal text may have the greater than and lower than operators as part of the text.
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-06 18:08:07 UTC
Yes, that fixed it.
Now – one more question – can I use the built in “icons” the ones in the font packages instead of having to put actual images in the folder ?
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-09-06 18:11:55 UTC
Yes for the icon packages, not for the theme icons. For the icon packages use the same url that comes with the static class: i.e. Wisej.Ext.MaterialDesign.Icons…. You can either use the full path resource.wx/Wisej.Ext.MaterialDesign/back-arrow.svg or the short path resource.wx/back-arrow.svg. In the second case, Wisej will return the first back-arrow.svg resource that it can find in the resource assemblies.
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-06 18:30:38 UTC
Tried it with ElegantIcons. Compiled the extension project and put the DLL in my project folder, added a reference to it.
Using img role=’test’ src=’ resource.wx/Wisej.Ext.EleganIcons/archive-box.svg’ – i just get the “X” in place of the image in the grid. The click even does work however. Just trying to sort out the graphic issue,
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-09-06 18:47:53 UTC
You have the wrong name EleganIcons instead of ElegantIcons. The “t” is missing. Also, since the images are svg images in an img element you can’t change the color. Wisej changes it by loading the svg xml document and changing the fill. Another option you have if you want to change the color is to use a real font icon set, which would work exactly as in any HTML page. Or you can change the color in the svg itself and save it back.
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-06 19:37:03 UTC
Luca, I corrected the spelling – but still no luck. Now the cell is blank – does not even show the “X” like before.
7 remaining items
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-07 02:47:44 UTC
I figured out what is going on, see attached screen shot. It appears that even with the style in your example added to default html - the size of the "font" icon is very large. When i stretched the cell wider - you can see how large it is. How can I set the size of the font ? Is this done in the Style as well ?
Sorry - coming from VWG we are not used to mixing HTML and C# to do this -although I see how powerful it is !
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-07 17:01:27 UTC
Looks like the image won't resize even though the style specifies the cell image as 16px X 16px
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-09-08 00:08:42 UTC
Hi Edmond,
I tried the snippet you sent like this:
in Default.html I have:
I get this:
SVG icons need the size because they are vectorial and usually designed on a large canvas, like 800x800. Setting the size on the img element directly or through css must work, it's part of the browser. I also tried IE11 and FireFox.
Best,
Luca
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-08 11:34:13 UTC
I got it to work as well early this AM. After I edited default.html again and set it to 32×32 it worked. Then I backed it down to 16×16 again and now it works. Strange, it’s almost as if the style was not being used in default.html until i edited it again.
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-08 11:49:04 UTC
Okay – after it worked, i added in another icon to the list in the html. Ran it again – icons don’t show up After some testing I figured out that if I edit Default HTML again and just change the size even just 2 px to 18px and run – they show up. I edit and add another icon to html – same issue. I put the px back to 18px, run – they show up. Put it back to 16px and they still show up.
If you want to do a screen share I can set one up so you can see it. Strange behavior.
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-08 11:56:28 UTC
It would be cool if in the HTML we could specify the fill color and when the resource is returned it can be the color specified. I like to limit the amount of free floating images on the deployment hard drive as much as possible. Maybe use the standard HTML # color tag ?
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-08 17:55:16 UTC
So it appears that unless i make a change to the default html style every time i change the HTML string, my changes to the HTML string do not work.
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-09-08 17:57:39 UTC
It’s the browser’s cache. One way around it it’s to use a css file and add a “?v=[counter]” to bust the cache.
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-09-08 18:01:28 UTC
The HTML color tag doesn’t work on svg images. The fill style only works on svg elements. Wisej performs the color change on the client but it kicks in only for Wisej widgets and during the image preloading. Wisej supports a ?color=[color] parameter already, but it can only be processed by Wisej widgets since we have to way of changing the way a src attribute in img works. The color could change could be processed on the server instead of the client but it’s kind of overkill. Another way to achieve this is to use a font icon set and use the css names and unicode entitired defined by the font, see font awesome for example. This is the main reason why when working just with HTML the svg icons had to be converted to fonts.
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-08 19:36:14 UTC
But once i set the style in default.html – why would i have to make an edit to it for the HTML in the datagrid to work ? I should only have to set the style one time and forget it right ?
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-09-08 19:38:42 UTC
Try to clear the cache or another browser or add a parameter to Default.htm?v=1. Looks like the browser is still retrieving the first Default.html without the style.
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-08 19:45:08 UTC
No – what happens is – its working – then after I edit the html in the datagrid cell to add another icon and I run it it stops showing the icons. It initially does until I edit the cell HTML again. Then it stops. The only way to get it to work again is to go and make a change to default.html – then it will show the icons again in the datagrid cell. Even if i just edit they style to 18px save it , then edit it again back to 16px, save it – then run. Then the Icons show up in the datagrid cell.
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-09-08 19:52:36 UTC
Tried that by adding img role=’test’ src=’resource.wx/Wisej.Ext.ElegantIcons/arrow-up.svg’ class=’cell-image’. It’s just html, if it doesn’t work there is a problem with the browser, cache, etc. Verify using F12 with Chrome, select Elements, click the button (top left) “Select an element…” and inspect the HTML. Select the img element and you should see on the right, under Styles and Computed, the effective style. That show show exactly what’s wrong.
itg-assistant commentedon Jun 12, 2026
edmond girardi answered 2017-09-08 20:04:00 UTC
Tried in Chrome and it works fine – made changes and ran without having to edit default.html every time. must be IE 11 issue as you said.