|
Query |
Response |
|
To select a range of cells and export that range to a datatable |
Inorder to export the selected range of cells to excel, SelectedExport() method is used. Please refer to the below code,
Code Example
GridExcelConverterControl ExcelAdv = new GridExcelConverterControl();
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Files(*.xlsx)|*.xlsx|Files(*.xls)|*.xls";
saveFileDialog.DefaultExt = ".xlsx";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
ExcelAdv.SelectedExport(this.gridControl1.Model, saveFileDialog.FileName, ConverterOptions.Default);
}
Please refer to the dashboard sample that is available in your local machine from the below location,
Sample Location: <Installed Location>\Syncfusion\EssentialStudio\<Installed version>\Windows\Grid.Windows\Samples\Exporting\Exporting Demo\CS
Please refer to the below UG link to know about exporting selected range of cells to excel,
|
|
To customize the fill series event slightly by having the cells highlight with a certain color when a series is filled. |
As per our current support, there is no event to customize the selected cells after FillSeries is applied to the Gridcells. However, you can set the back color of the selected range of cells before the FillSeries is applied, by handling MouseUp event. Please make use of the below code and sample,
Code Example
private void GridControl1_MouseUp(object sender, MouseEventArgs e)
{
int row, col;
gridControl1.PointToRowCol(new Point(e.X, e.Y), out row, out col);
GridRangeInfo r = gridControl1.Selections.Ranges.ActiveRange;
if (r.Bottom != row && r.Right != col)
{
int top = r.Top; int right = r.Right;
for (int i = top; i <= row; i++)
{
for (int j = right; j <= col; j++)
{
gridControl1[i, j].BackColor = Color.Red;
}
}
} |
|
private void button1_Click(object sender, EventArgs e)
{
var range = this.gridControl1.Model.SelectedRanges.ActiveRange;
int col = range.Right - range.Left + 1;
int row = range.Bottom - range.Top + 1;
int top = range.Top;
int left = range.Left;
int Bottom = range.Bottom;
int right = range.Right;
int l = left;
int t = top;
DataTable dt = new DataTable();
for (int c = 0; c < col; c++)
{
string colName = gridControl1.Model[0, l].Text;
l++;
dt.Columns.Add(colName);
}
l = left;
for (int i = 0; i < row; i++)
{
DataRow dr = dt.NewRow();
for (int j = 0; j < col; j++)
{
dr[j] = this.gridControl1.Model[t, l].Text;
l++;
}
dt.Rows.Add(dr);
t++;
l = left;
}
gridControl1.RowCount = dt.Rows.Count;
gridControl1.ColCount = dt.Columns.Count;
} |