This is a migrated thread and some comments may be shown as answers.

ExportStructure Row Count

6 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 13 Nov 2014, 10:13 PM
Hi all,

I'm using ExportStructure to export the grid to Excel.
I create a Table named tb and use tb.Cells to write contents.

However, tb.Rows.Count is always zero, even when data is there. Export happens as expected though.

Any idea?

I have to know how many rows a given Table (of ExportStructure) has.

Thank you!

6 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 18 Nov 2014, 12:55 PM
Hi Igor,

The reason Rows count to be zero is because you fill the cell with data without creating a row objects. In case you need to access the number of rows you have to create a new row object. Note that a new row object is created automatically when you access it by an index. Please check out the following code snippet. 
protected void Button1_Click(object sender, EventArgs e)
{
    ei.ExportStructure structure = new ei.ExportStructure();
    ei.Table table = new ei.Table();
    ei.Row row;
    for (int i = 0; i < 10; i++)
    {
        row = table.Rows[i];
        for (int j = 0; j < 10; j++)
        {
            row.Cells[i, j].Value = "Col" + i + "Row" + j;
        }
    }
    structure.Tables.Add(table);
}

Nevertheless since you are creating the table manually you already know the number of rows so you can create a property which holds this information and use it whenever you need it.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Igor
Top achievements
Rank 1
answered on 21 Nov 2014, 05:28 PM
You are using
row.Cells[i,j]
 but should be
[j,i]
 right? i is Row and j is Column.
0
Igor
Top achievements
Rank 1
answered on 21 Nov 2014, 05:39 PM
Also,
The code is not working. The Cell Value is always empty, even after I assign a value.
I'm using VB.NET:

rowExport = tb.Rows(1)
rowExport.Cells(1, 1).Value = "Test"

Value is still Nothing after execution.
0
Kostadin
Telerik team
answered on 26 Nov 2014, 12:45 PM
Hi Igor,

Please excuse me for misleading you in my previous reply. You need to get the Cell object from the Table and not from the Row object. Please try the following code and let me know about the result.
protected void Button1_Click(object sender, EventArgs e)
{
    ei.ExportStructure structure = new ei.ExportStructure();
    ei.Table table = new ei.Table();
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            table.Cells[j, i].Value = "Col" + i + "Row" + j;
        }
    }
    structure.Tables.Add(table);
}


Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Igor
Top achievements
Rank 1
answered on 26 Nov 2014, 03:21 PM
Thank you, using the Table's Cell object worked.
Just some points:

1- in your latest example, you forgot to "create" the row via

row = table.Rows[i];


right before the columns (j) loop.

2- I believe your i and j has the wrong meaning. j should be cols and i should be rows, taking into consideration the signature of Cells object.

I couldn't find any documentation about this issue (Rows creation) in your website. The documentation for ExportStructure needs to be improved.

Thank you.
0
Kostadin
Telerik team
answered on 01 Dec 2014, 08:16 AM
Hello Igor,

Note that in most cases you will not need to access the number of row by checking the Rows collection object. Basically when you create the structure programmatically you already know the numbers of rows and in my case they are 10.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Igor
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Igor
Top achievements
Rank 1
Share this question
or