For gridcontrol, I know to get all cell value by loop through each cell like following code:
for (int i = 1;i
AD
Administrator
Syncfusion Team
September 16, 2004 03:17 PM UTC
Hi,
try calling
FieldDescriptor field = groupingControl.TableDescriptor.Columns[columnName].FieldDescriptor;
groupingControl.Table.Records[recordNum].GetValue(field);
whereas recordNum is the record number and
columnName the name of the column.
Stefan
AD
Administrator
Syncfusion Team
September 16, 2004 03:22 PM UTC
One more thing. If you have a rowIndex and colIndex and what to know all about the cell that is displayed, you should get its TableCellIdentity:
GridStyleInfo style = gridModel[rowIndex, colIndex];
GridTableCellStyleInfo tStyle = (GridTableCellStyleInfo);
GridTableCellStyleInfoIdentity id = tStyle.TableCellIdentity;
// id has information about DisplayElement, Column, SummaryColumn etc.
The record displayed at the row is DisplayElement.ParentRecord
Stefan
AD
Administrator
Syncfusion Team
September 16, 2004 04:00 PM UTC
Hi Stephan,
While this works for most cells in the grid, a problem still exists when a column contains a combobox whose displayvalue is a string but the underlying table field value is a numeric value. The code exports the numeric value. How can I get the cell''s displayvalue instead?
>Hi,
>
>try calling
>
>FieldDescriptor field = groupingControl.TableDescriptor.Columns[columnName].FieldDescriptor;
>
>groupingControl.Table.Records[recordNum].GetValue(field);
>
>whereas recordNum is the record number and
>columnName the name of the column.
>
>Stefan
>
AD
Administrator
Syncfusion Team
September 16, 2004 05:16 PM UTC
When you have the Style for the field, you can call its FormattedText property.
If you need to get the rowIndex from a given record index, you could use the following:
Record r;
int rowIndex = Table.DisplayElements.IndexOf(r);
// Now you have the row index
If you need to get the column index from a column descriptor
int colIndex = Table.TableDescriptor.VisibleColumns.IndexOf(columnName);
if (colIndex != -1)
colIndex += Table.TableDescriptor.GetColumnIndentCount();
We''ll also have more advanced for foreign keys in our next version - then you''ll simply be able to call something like record.GetValue("RelatedTable.DisplayFieldName") which will be much easier.
Stefan
AD
Administrator
Syncfusion Team
September 20, 2004 02:22 PM UTC
I haven''t quite understand your code. Here is my routine to export GridGropingControl cell data to Excell. Could tell me where I should put the code to get the Display value instead of code:
private void ExportToExcelFile(string FileName)
{
this.Cursor=Cursors.WaitCursor;
this.Refresh();
IWorkbook myWorkBook = ExcelUtils.CreateWorkbook(1);
IWorksheet sheet = myWorkBook.Worksheets[0];
for (int i=0;iWhen you have the Style for the field, you can call its FormattedText property.
>
>If you need to get the rowIndex from a given record index, you could use the following:
>
>Record r;
>int rowIndex = Table.DisplayElements.IndexOf(r);
>
>// Now you have the row index
>
>If you need to get the column index from a column descriptor
>
>int colIndex = Table.TableDescriptor.VisibleColumns.IndexOf(columnName);
>if (colIndex != -1)
>colIndex += Table.TableDescriptor.GetColumnIndentCount();
>
>We''ll also have more advanced for foreign keys in our next version - then you''ll simply be able to call something like record.GetValue("RelatedTable.DisplayFieldName") which will be much easier.
>
>Stefan
>
>
AD
Administrator
Syncfusion Team
September 20, 2004 03:10 PM UTC
I think this should work:
private void ExportToExcelFile(string FileName)
{
this.Cursor=Cursors.WaitCursor;
this.Refresh();
IWorkbook myWorkBook = ExcelUtils.CreateWorkbook(1);
IWorksheet sheet = myWorkBook.Worksheets[0];
Hashtable colIndexMapping = new Hashtable();
int count = gd.TableModel.ColCount;
int colIndex = -1;
for (int i = 0; i < count; i++)
{
GridColumnDescriptor cd = gd.Table.GetHeaderColumnDescriptorAt(i);
if (cd != null)
colIndexMapping[cd.Name] = i;
}
for (int i=0;i {
FieldDescriptor field = gdBase.TableDescriptor.Columns[i].FieldDescriptor;
string sFieldName=field.Name;
sheet.Range[1,i+1].Text=sFieldName;
//sheet.Range[1,i+1].Value2 =sFieldName;
sheet.Range[1,i+1].CellStyle.Font.Bold = true;
}
for (int i=0;i {
string sFieldName=gdBase.TableDescriptor.Columns[i].Name;
//FieldDescriptor field = gdBase.TableDescriptor.Columns[i].FieldDescriptor;
for(int j=0; j {
Record r = gdBase.Table.Records[j];
int rowIndex = gdBase.Table.DisplayElements.IndexOf(r);
int colIndex = (int) colIndexMapping[gdBase.TableDescriptor.Columns[i].Name];
sheet.Range[j+2,i+1].Text = gdBase.Model[rowIndex, colIndex].FormattedText;
}
}
#region Saving Workbook
myWorkBook.SaveAs(FileName);
myWorkBook.Close();
ExcelUtils.ThrowNotSavedOnDestroy = false;
this.Cursor=Cursors.Default;
# endregion
}
Stefan