Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Add button in cell. (Read 6484 times)
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Add button in cell.
Dec 17th, 2020 at 8:51am
Print Post  
Hello,

Is possible too add button in a cell that it can trigger event when click it.

Thanks

David Chiang
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Add button in cell.
Reply #1 - Dec 17th, 2020 at 10:31am
Print Post  
Hi,

Do you need button to show only for currently active cell, or for a cell on specific position / all cells? For current cell, it could probably be done by inserting a button into the cell-edit UI. For other cases, we'll have to think of something more complex...

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: Add button in cell.
Reply #2 - Dec 17th, 2020 at 10:45am
Print Post  
Thanks for the reply. What I need is for adding one or more button for each row of data. When click the button, which will trigger a event to popup a window or some other action. Do you have example to testing... Thanks a lot.



                       for (int x = 0; x < recCount; x++)
                       {
                             kk = 0;
                             dataRow = dataTable.Rows[x];
                             for (int k = 0; k < columnsVisible.Count; k++)
                             {
                                   //Console.WriteLine("rptExcel 148 : " + " k = " + k + "  datae = " + columnsVisible[k]);
                                   if (columnsVisible[k] == "1")
                                   {
                                         var cell = activeSheet.Cells[k - kk, x + 1];
                                         //cell.Data =dataRow[k].ToString();
                                         cell.Data = ParsingJson.ConvertParamData(colLinkType[k], colLinkID[k], dataRow[k].ToString(), jsonOther, AboutParam.jsonLang);
                                         GenerateRandomFont(ref cell);
                                   }
                                   else kk++;
                             }
                       }


Adding button inside the cell

David Chiang
  
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: Add button in cell.
Reply #3 - Dec 17th, 2020 at 10:56am
Print Post  
Or I can use Hyperlink instead? Any sample.

Thanks
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Add button in cell.
Reply #4 - Dec 17th, 2020 at 11:02am
Print Post  
Maybe try styling cells themselves to look like hyperlinks or buttons, and then run your action from CellClicked event. If you need actual buttons, we could extend the embedded objects system (e.g. images / annotations) to support custom controls for next release.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Add button in cell.
Reply #5 - Dec 17th, 2020 at 11:06am
Print Post  
David Chiang wrote on Dec 17th, 2020 at 10:56am:
Or I can use Hyperlink instead? Any sample.

Thanks


You can find hyperlinks used in ReadyWorkbooks example, implementing a table of contents. You could intercept hyperlink clicks via WorkbookView.HyperlinkClicked event handler.
  
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: Add button in cell.
Reply #6 - Dec 17th, 2020 at 11:29am
Print Post  
Any example by code behind? Like sample code I put.  How to WorkbookView.HyperlinkClicked popup new window?

Thanks

David Chiang
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Add button in cell.
Reply #7 - Dec 17th, 2020 at 11:41am
Print Post  
Code
Select All
activeSheet.Cells["A1"].SetHyperlink(HyperlinkType.WebAddress, "1", "");
workbookView.HyperlinkClicked +=
    (sender, args) => MessageBox.Show(args.Cell.Value.ToString()); 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: Add button in cell.
Reply #8 - Dec 17th, 2020 at 12:01pm
Print Post  
Here is code I used.

                                         var cell = activeSheet.Cells[k - kk, x + 1];
                                         //cell.Data =dataRow[k].ToString();
                                         cell.Data = ParsingJson.ConvertParamData(colLinkType[k], colLinkID[k], dataRow[k].ToString(), jsonOther, AboutParam.jsonLang);
                                         cell.SetHyperlink(HyperlinkType.WebAddress, ParsingJson.ConvertParamData(colLinkType[k], colLinkID[k], dataRow[k].ToString(), jsonOther, AboutParam.jsonLang), "");
                                         workbookView.HyperlinkClicked +=
                                               (sender, args) => MessageBox.Show(args.Cell.Value.ToString());
                                         GenerateRandomFont(ref cell);


But I am not able to close the messagebox. It keep pop up.
it will popup 5302 times

                                         workbookView.HyperlinkClicked +=
                                               (sender, args) => showWindow();


           void showWindow()
        {
                 Console.WriteLine("KKK");
           }



if I only use

cell.SetHyperlink(HyperlinkType.WebAddress, ParsingJson.ConvertParamData(colLinkType[k], colLinkID[k], dataRow[k].ToString(), jsonOther, AboutParam.jsonLang), "");

the data will not show up.

Thanks

David Chiang
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Add button in cell.
Reply #9 - Dec 17th, 2020 at 6:15pm
Print Post  
Quote:
But I am not able to close the messagebox. It keep pop up.
it will popup 5302 times

workbookView.HyperlinkClicked +=
(sender, args) => showWindow();


That's some patience to count them all Wink Sounds like you've attached the event handler 5302 times - are you maybe looping over all rows and calling HyperlinkClicked += code for each one? In such case, try moving that outside of the loop. I.e. not like this -

Code
Select All
foreach (row...)
{
    workbookView.HyperlinkClicked +=
        (sender, args) => showWindow();
    // set hyperlink
} 



but like this

Code
Select All
workbookView.HyperlinkClicked +=
    (sender, args) => showWindow();
foreach (row...)
{
    // set hyperlink
} 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: Add button in cell.
Reply #10 - Dec 18th, 2020 at 12:51am
Print Post  
Thanks a lot Cheesy, any sample to make the cell style like button? Since I like to hide data in behind, Usually I use TAG but there is no TAG attribute in cell. Is there any place I can hide the data?


BTW. How to show the long number to string instead of 1.3434+12?

Is there anyway I can do like

                                               cell.SetAnnotation(dataRow[k].ToString());
cell.SetAnnotation.Visibility = Visibility.Hidden ;
cell.SetHyperlink(HyperlinkType.WebAddress, ParsingJson.ConvertParamData(colLinkType[k], colLinkID[k], dataRow[k].ToString(), jsonOther, AboutParam.jsonLang), "");


Or How do I  inserting a button into the cell-edit UI? Any sample for that.

Thanks again

David Chiang
« Last Edit: Dec 18th, 2020 at 7:11am by David Chiang »  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Add button in cell.
Reply #11 - Dec 18th, 2020 at 11:27am
Print Post  
Quote:
Since I like to hide data in behind, Usually I use TAG but there is no TAG attribute in cell. Is there any place I can hide the data?


There's a Row.Tag property you could use to store custom data. Since you'll have one button / link per row, maybe that's enough?

If you need to associate data with individual cells, maybe use Excel's approach where people keep misc. data in separate worksheet. E.g. you could also set that worksheet's Visible property to false to hide it from users.
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Add button in cell.
Reply #12 - Dec 18th, 2020 at 11:38am
Print Post  
Quote:
BTW. How to show the long number to string instead of 1.3434+12?


Try setting cell's Style.Format to one different than General, e.g. "0".
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Add button in cell.
Reply #13 - Dec 18th, 2020 at 11:51am
Print Post  
Quote:
Thanks a lot Cheesy, any sample to make the cell style like button?
Or How do I inserting a button into the cell-edit UI? Any sample for that.


You could set some background and border in cell's Style to make it look (a bit) like a button, e.g. as in attached screenshot. If you need a more elaborate appearance than that, we'll have in mind some custom drawing or embedding actual buttons for next release.

Regards,
Slavcho
Mindfusion
  

styled_cell.png ( 64 KB | 138 Downloads )
styled_cell.png
Back to top
 
IP Logged
 
David Chiang
Junior Member
**
Offline


I Love MindFusion!

Posts: 75
Joined: Apr 15th, 2020
Re: Add button in cell.
Reply #14 - Dec 18th, 2020 at 11:58am
Print Post  
Thanks for the reply. The cell format is working now and I might have more then one button per ROW. How can I inserting a button into the cell-edit UI? That I can use button's TAG to hide the data. Any sample for that.

Or the about answer is the way to do?


Thanks a lot

David Chiang
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint