GridWeb1.SelectCells is null

Hi to all,
I have created a CustomCommand named “Add Formula” and in the event CustomCommand I am trying to get a selected cell value (or at least first cell value of the selected cells arraylist) and transform this into a formula in this way:

((Aspose.Cells.GridWeb.Data.WebCell)((ArrayList)GridWeb1.SelectCells[0])[0]).Formula = ((Aspose.Cells.GridWeb.Data.WebCell)((ArrayList)GridWeb1.SelectCells[0])[0]).Value.ToString();

But I can’t do this because when I fire the event CustomCommand and I do not select from client a whole row, GridWeb1.SelectCells is null.
When I select a whole row instead, GridWeb1.SelectCells is no more null, but that is really not what I need.
Is there a way to get value of just one cell on server side (exactly in CustomCommand event)?
Could somone help me about this issue?



Hi,

Thanks for your posting and using Aspose.Cells for GridWeb.

Please download and use the latest version:
Aspose.Cells
for GridWeb v2.7.5.2001

and let us know your feedback.

I am attaching a custom command button sample, please look into it, run and incorporate it in your code and see if it is helpful in resolving your issue.

If it does not resolve your issue. I will need your simpler runnable project and screenshots that explains your problem in detail. Please highlight the points of interests with red circles.

For GridWeb1_CustomCommand event, it is based on a custom button, you should customize a custom button in GridWeb control, such as,<o:p></o:p>

<CustomCommandButtons>

<acw:CustomCommandButton

runat=“server”
Command=“HelloWorld”
ImageUrl=“/Grid/acw_client/save.gif”
><o:p></o:p>

</acw:CustomCommandButton>

</CustomCommandButtons>

Then for the GridWeb1_CustomCommand event, it will be called.

Following is the similar code:

switch (command.ToLower())

{

case "helloworld":

string script;

script = "";

this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Util.alertMessage", script);

break;<o:p></o:p>

case "":

break;

default:<o:p></o:p>

break;

}

I have attached an example, hope that you will know how you can customize your own event

Hi,


Could you try to use:

int r = ((WebCell)((ArrayList)GridWeb1.SelectCells[0])[0]).Row;
int c = ((WebCell)((ArrayList)GridWeb1.SelectCells[0])[0]).Column;

Now you would got row and column indices for the cell.

Thank you.
									Thanks to mshakeel.faiz and Amjad for your quick reply and examples, but I haven't resolved my issue yet. Maybe I have some difficulties to understand.<br>So I will post here my code to give some more info as request.<br>This is my designer code:<br><i><br><br><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="Aspose.Test" %><br><%@ Register TagPrefix="agw" Namespace="Aspose.Cells.GridWeb" Assembly="Aspose.Cells.GridWeb" %><br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br><html xmlns="http://www.w3.org/1999/xhtml" ><br><head runat="server"><br>    <title>Aspose Test</title><br></head><br><body><br>    <form id="form1" runat="server"><br>        <script type="text/javascript"><br>        function onCellSelected(cell)<br>        {<br>            document.getElementById("<%=HiddenField1.ClientID%>").value = this.getCellValueByCell(cell);<br>        }<br>        </script><br>        <asp:TextBox ID="txtMessages" runat="server" Height="100px" Width="335px" TextMode="MultiLine"></asp:TextBox><br>        <agw:GridWeb id="GridWeb1" runat="server" XhtmlMode="True" <br>            OnSaveCommand="GridWeb1_SaveCommand" EditMode="true"<br>            onsubmitcommand="GridWeb1_SubmitCommand" DefaultGridLineColor="#FFCC66" <br>            AutoExtendMaxRowColumn="False" <br>            SessionMode="ViewState" oncustomcommand="GridWeb1_CustomCommand" <br>            oncelldoubleclick="GridWeb1_CellDoubleClick" <br>            oncellselectedclientfunction="onCellSelected"><br>            <WebWorksheets><br>                <agw:Worksheet runat="server" Name="Sheet1" DataMember=""></agw:Worksheet><br>            </WebWorksheets>                            <br>            <CustomCommandButtons><br>                <agw:CustomCommandButton Command="AddFormula" Text="Add Formula" CommandType="ContextMenuItem"></agw:CustomCommandButton><br>                <agw:CustomCommandButton Command="TypeCell" Text="Cell Type" CommandType="CommandButton"></agw:CustomCommandButton><br>                <agw:CustomCommandButton runat="server" Command="HelloWorld" Text="Hello World" CommandType="CommandButton" ></agw:CustomCommandButton><br>            </CustomCommandButtons><br>        </agw:GridWeb><br>    </form><br></body><br></html></i><br><br><br>And that is my aspx cs code:<br><br><br><i>using System;<br>using System.Collections;<br>using System.Web.UI;<br>using Aspose.Cells.GridWeb;<br><br>namespace Aspose<br>{<br>    public partial class Test : System.Web.UI.Page<br>    {</i><br><i>        protected void Page_Load(object sender, EventArgs e)<br>       {<br>             Aspose.Cells.License license = new Aspose.Cells.License();<br>            license.SetLicense("Aspose.Cells.lic");<br><br>            if (!Page.IsPostBack && !Page.IsCallback)<br>            {<br>                GridWeb1.WebWorksheets.Clear();<br>                GridWeb1.WebWorksheets.ImportExcelFile([serverpath]+ filename);<br>                //GridWeb1.WebWorksheets.RunAllFormulas(); <br>            }<br>        }<br><br>        protected void GridWeb1_CustomCommand(object sender, string command)<br>        {<br>             </i><b>//When debug is on this instruction GridWeb1.SelectCells is null. <br>             //In other word SelectCells arraylist is null <br>             //but only if just one row is selected <br>             //otherwise (a whole row) SelectedCells is valued</b><i><br>             int r = ((Aspose.Cells.GridWeb.Data.WebCell)((ArrayList)GridWeb1.SelectCells[0])[0]).Row;<br>             int c = ((Aspose.Cells.GridWeb.Data.WebCell)((ArrayList)GridWeb1.SelectCells[0])[0]).Column;<br>            //So, these 2 instructions generate an object reference null error<br>             try<br>            {<br>                switch (command)<br>                {<br>                    case "HelloWorld":<br>                        string script;<br>                        script = "<script language='javascript'>alert('"<br>                               + "Hello World"<br>                               + "')</script>";<br>                        this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Util.alertMessage", script);<br>                        break;<br>                    case "AddFormula":<br>                        txtMessages.Text += (GridWeb1.SelectCells.Count > 0) ? GridWeb1.SelectCells.Count.ToString() : "null";<br>                        txtMessages.Text += "\n\r";<br>                        ((Aspose.Cells.GridWeb.Data.WebCell)((ArrayList)GridWeb1.SelectCells[0])[0]).Formula = ((Aspose.Cells.GridWeb.Data.WebCell)((ArrayList)GridWeb1.SelectCells[0])[0]).Value.ToString();<br>                        GridWeb1.WebWorksheets.RunAllFormulas();<br>                        break;<br>                    case "TypeCell":<br>                        break;<br>                }<br>            }<br>            catch (Exception ex)<br>            {<br>                txtMessages.Text += "Source: " + ex.Source + "\n\rMess: " + ex.Message;<br>            }<br>        }</i><br>    <i>}<br>}</i><br><br>Why<i> </i>is <i>SelectedCells</i> null in <i>CustomCommand </i>event when I select just one cell?<br>Where have I done wrong? maybe some parameter of GridWeb?<br>Should I just use javascript <i>oncellselectedclientfunction</i> to get just one cell selection as above and in some way returning the value on server side?<br>What I want is just get one cell value in CustomCommand event.<br>So I will transform user text input in a formula (of course if user click on "Add Formula").<br>Thanks in advance,<br>Roby<br>

Hi,


If you need to get / set cell value or even select or activate cell on the sheet, please use our client side functions, see the demo:


Here you will find some valuable client side functions/methods, e.g
get/setCellValue, get/setActiveRow, get/setActiveColumn, get/setCellXXXX etc.

Also, we will also try to evaluate your issue regarding SelectCells. I have logged a ticket with an id: CELLSNET-40594, once we have any update on it, we will let you know here.

Thank you.

Hi,

We have fixed this bug. Please download and use the latest: Aspose.Cells for GridWeb v2.7.5.2002

The issues you have found earlier (filed as CELLSNET-40594) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.