I have created a telerik report using Visual Studio and set the Datasource from the DataTable. I am creating the columns dynamically at runtime using Telerik.Reporting.TableGroup. Now the problem I am having here is that the report showing the same data for all of the fields and when I debug it is setting different fields for different.
The code I am using is as follows:
private void Report4_NeedDataSource(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt = SalesReport.reportDataTable;
table1.DataSource = dt;
Telerik.Reporting.HtmlTextBox textboxGroup;
Telerik.Reporting.HtmlTextBox textBoxTable;
table1.ColumnGroups.Clear();
table1.Body.Columns.Clear();
table1.Body.Rows.Clear();
int ColCount = dt.Columns.Count;
for (int i = 0; i <= ColCount - 1; i++)
{
Telerik.Reporting.TableGroup tableGroupColumn = new Telerik.Reporting.TableGroup();
table1.ColumnGroups.Add(tableGroupColumn);
textboxGroup = new Telerik.Reporting.HtmlTextBox();
textboxGroup.Style.BorderColor.Default = Color.Black;
textboxGroup.Style.BorderStyle.Default = BorderType.Solid;
textboxGroup.Value = dt.Columns[i].ColumnName;
textboxGroup.Size = new SizeU(Unit.Inch(1.5), Unit.Inch(0.6));
tableGroupColumn.ReportItem = textboxGroup;
textBoxTable = new Telerik.Reporting.HtmlTextBox();
textBoxTable.Value = "=Fields." + dt.Columns[i].ColumnName;
textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
table1.Body.SetCellContent(0, i, textBoxTable);
table1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });
}
}
I suggest reading the following article. I found this same problem and my solution was to add unique names to the group column, label, and detail text boxes.
http://www.telerik.com/forums/incorrect-dynamic-table-columns
//Added
tableGroupColumn.Name = "group" + *something_uniquegoeshere*;
//Added
textboxGroup.Name = "label" + *something_uniquegoeshere*;
//Added
textBoxTable.Name = "data" + *something_uniquegoeshere*;
Not enough space in a comment unfortunately but here's my advice/suggestion. I'm not certain about your specific error, however in the past I have had issues when re-using variables. You declare your variable outside the for statement and it is possible that this is what is causing the problem.
private void Report4_NeedDataSource(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt = SalesReport.reportDataTable;
table1.DataSource = dt;
//Telerik.Reporting.HtmlTextBox textboxGroup;
//Telerik.Reporting.HtmlTextBox textBoxTable;
table1.ColumnGroups.Clear();
table1.Body.Columns.Clear();
table1.Body.Rows.Clear();
int ColCount = dt.Columns.Count;
for (int i = 0; i <= ColCount - 1; i++)
{
Telerik.Reporting.TableGroup tableGroupColumn = new Telerik.Reporting.TableGroup();
table1.ColumnGroups.Add(tableGroupColumn);
var textboxGroup = new Telerik.Reporting.HtmlTextBox();
textboxGroup.Style.BorderColor.Default = Color.Black;
textboxGroup.Style.BorderStyle.Default = BorderType.Solid;
textboxGroup.Value = dt.Columns[i].ColumnName;
textboxGroup.Size = new SizeU(Unit.Inch(1.5), Unit.Inch(0.6));
tableGroupColumn.ReportItem = textboxGroup;
var textBoxTable = new Telerik.Reporting.HtmlTextBox();
textBoxTable.Value = "=Fields." + dt.Columns[i].ColumnName;
textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
table1.Body.SetCellContent(0, i, textBoxTable);
table1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });
}
}
I have program but when I want to send them to Excel from datagridview some of the there Columns well be changed in Excel
I will appreciate if any friend can help me.
You can see code in below
The above problem in Columns Cm-1 Till Rm-12
It shows in Excel 0,1,2,3,....
private void button1_Click(object sender, EventArgs e)//Export To Exel
{
OleDbConnection ocon;
OleDbCommand ocom;
OleDbDataAdapter oda;
OleDbCommandBuilder ocb;
saveFileDialog1.ShowDialog();
ocon = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + saveFileDialog1.FileName + "; Extended Properties=Excel 8.0;");
ocom = ocon.CreateCommand();
ocon.Open();
ocom.CommandText = "CREATE table [Consumption](Geo_Market char(20),location char(20),segment_id char(20),Parent_store_Name char(20),store_Name char(20),store_Level char(20),Sub_Sub_Segment char(20),part_no char(20),Part_Description char(20),part_Type char(20),QTY Integer,UOM char(20),price Integer,Averag_Stock_Value Integer,min_level Integer,max_level Integer,part_location char(20),[CM-1] Integer,[CM-2] Integer,[CM-3] Integer,[CM-4] Integer,[CM-5] Integer,[CM-6] Integer,[CM-7] Integer,[CM-8] Integer,[CM-9] Integer,[CM-10] Integer,[CM-11] Integer,[CM-12] Integer,[RM-1] Integer,[RM-2] Integer,[RM-3] Integer,[RM-4] Integer,[RM-5] Integer,[RM-6] Integer,[RM-7] Integer,[RM-8] Integer,[RM-9] Integer,[RM-10] Integer,[RM-11] Integer,[RM-12] Integer,last_issue_date Char(20),Excess_qty Integer,Excess_value Integer,Slow_Move char(20))";
ocom.ExecuteNonQuery();
ocom.Parameters.Add("Geo_Market", OleDbType.Char);//0
ocom.Parameters.Add("location", OleDbType.Char);//1
ocom.Parameters.Add("segment_id", OleDbType.Char);//2
ocom.Parameters.Add("Parent_store_Name", OleDbType.Char);//3
ocom.Parameters.Add("store_Name", OleDbType.Char);//4
ocom.Parameters.Add("store_Level", OleDbType.Char);//5
ocom.Parameters.Add("Sub_Sub_Segment", OleDbType.Char);//6
ocom.Parameters.Add("part_no", OleDbType.Char);//7
ocom.Parameters.Add("Part_Description", OleDbType.Char);//8
ocom.Parameters.Add("part_Type", OleDbType.Char);//9
ocom.Parameters.Add("QTY", OleDbType.Integer);//10
ocom.Parameters.Add("UOM", OleDbType.Char);//11
ocom.Parameters.Add("price", OleDbType.Decimal);//12
ocom.Parameters.Add("Averag_Stock_Value", OleDbType.Decimal);//13
ocom.Parameters.Add("min_level", OleDbType.Integer);//14
ocom.Parameters.Add("min_level", OleDbType.Integer);//15
ocom.Parameters.Add("part_location", OleDbType.Char);//16
ocom.Parameters.Add("CM-1", OleDbType.Integer);//17
ocom.Parameters.Add("CM-2", OleDbType.Integer);//18
ocom.Parameters.Add("CM-3", OleDbType.Integer);//19
ocom.Parameters.Add("CM-4", OleDbType.Integer);//20
ocom.Parameters.Add("CM-5", OleDbType.Integer);//21
ocom.Parameters.Add("CM-6", OleDbType.Integer);//22
ocom.Parameters.Add("CM-7", OleDbType.Integer);//23
ocom.Parameters.Add("CM-8", OleDbType.Integer);//24
ocom.Parameters.Add("CM-9", OleDbType.Integer);//25
ocom.Parameters.Add("CM-10", OleDbType.Integer);//26
ocom.Parameters.Add("CM-11", OleDbType.Integer);//27
ocom.Parameters.Add("CM-12", OleDbType.Integer);//28
ocom.Parameters.Add("RM-1", OleDbType.Integer);//29
ocom.Parameters.Add("RM-2", OleDbType.Integer);//30
ocom.Parameters.Add("RM-3", OleDbType.Integer);//31
ocom.Parameters.Add("RM-4", OleDbType.Integer);//32
ocom.Parameters.Add("RM-5", OleDbType.Integer);//33
ocom.Parameters.Add("RM-6", OleDbType.Integer);//34
ocom.Parameters.Add("RM-7", OleDbType.Integer);//35
ocom.Parameters.Add("RM-8", OleDbType.Integer);//36
ocom.Parameters.Add("RM-9", OleDbType.Integer);//37
ocom.Parameters.Add("RM-10", OleDbType.Integer);//38
ocom.Parameters.Add("RM-11", OleDbType.Integer);//39
ocom.Parameters.Add("RM-12", OleDbType.Integer);//40
ocom.Parameters.Add("last_issue_date", OleDbType.Char);//41
ocom.Parameters.Add("Excess_qty", OleDbType.Integer);//42
ocom.Parameters.Add("Excess_value", OleDbType.Integer);//43
ocom.Parameters.Add("Slow_Move", OleDbType.Char);//44
//// چون که اکسپور شود دکمه گو را توی Go buttom ra dar yek dat2 ke dar bala creat kardam rikhtam
for (int dr = 0; dr < dataGridView1.Rows.Count - 1; dr++)
{
ocom.Parameters[0].Value = (string)dataGridView1.Rows[dr].Cells[0].Value;
ocom.Parameters[1].Value = (string)dataGridView1.Rows[dr].Cells[1].Value;
ocom.Parameters[2].Value = (string)dataGridView1.Rows[dr].Cells[2].Value;
ocom.Parameters[3].Value = (string)dataGridView1.Rows[dr].Cells[3].Value;
ocom.Parameters[4].Value = (string)dataGridView1.Rows[dr].Cells[4].Value;
ocom.Parameters[5].Value = (string)dataGridView1.Rows[dr].Cells[5].Value;
ocom.Parameters[6].Value = (string)dataGridView1.Rows[dr].Cells[6].Value;
ocom.Parameters[7].Value = (string)dataGridView1.Rows[dr].Cells[7].Value;
ocom.Parameters[8].Value = (string)dataGridView1.Rows[dr].Cells[8].Value;//(Int64)
ocom.Parameters[9].Value = (string)dataGridView1.Rows[dr].Cells[9].Value;//(Int64)
ocom.Parameters[10].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[10].Value);//(int)
ocom.Parameters[11].Value = (string)dataGridView1.Rows[dr].Cells[11].Value;//(int)
ocom.Parameters[12].Value = Convert.ToDecimal(dataGridView1.Rows[dr].Cells[12].Value);
ocom.Parameters[13].Value = Convert.ToDecimal(dataGridView1.Rows[dr].Cells[13].Value);
ocom.Parameters[14].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[14].Value);
ocom.Parameters[15].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[15].Value);
ocom.Parameters[16].Value = (string)dataGridView1.Rows[dr].Cells[16].Value;
ocom.Parameters[17].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[17].Value);//cm1
ocom.Parameters[18].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[18].Value);
ocom.Parameters[19].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[19].Value);
ocom.Parameters[20].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[20].Value);
ocom.Parameters[21].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[21].Value);
ocom.Parameters[22].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[22].Value);
ocom.Parameters[23].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[23].Value);
ocom.Parameters[24].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[24].Value);
ocom.Parameters[25].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[25].Value);
ocom.Parameters[26].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[26].Value);
ocom.Parameters[27].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[27].Value);
ocom.Parameters[28].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[28].Value);
ocom.Parameters[29].Value = (string)dataGridView1.Rows[dr].Cells[29].Value;
ocom.Parameters[30].Value = (string)dataGridView1.Rows[dr].Cells[30].Value;
ocom.Parameters[31].Value = (string)dataGridView1.Rows[dr].Cells[31].Value;
ocom.Parameters[32].Value = (string)dataGridView1.Rows[dr].Cells[32].Value;
ocom.Parameters[33].Value = (string)dataGridView1.Rows[dr].Cells[33].Value;
ocom.Parameters[34].Value = (string)dataGridView1.Rows[dr].Cells[34].Value;
ocom.Parameters[35].Value = (string)dataGridView1.Rows[dr].Cells[35].Value;
ocom.Parameters[36].Value = (string)dataGridView1.Rows[dr].Cells[36].Value;
ocom.Parameters[37].Value = (string)dataGridView1.Rows[dr].Cells[37].Value;
ocom.Parameters[38].Value = (string)dataGridView1.Rows[dr].Cells[38].Value;
ocom.Parameters[39].Value = (string)dataGridView1.Rows[dr].Cells[39].Value;
ocom.Parameters[40].Value = (string)dataGridView1.Rows[dr].Cells[40].Value;
ocom.Parameters[41].Value = (string)dataGridView1.Rows[dr].Cells[41].Value;
ocom.Parameters[42].Value = Convert.ToInt32(dataGridView1.Rows[dr].Cells[42].Value);
ocom.Parameters[43].Value = Convert.ToDecimal(dataGridView1.Rows[dr].Cells[43].Value);
ocom.Parameters[44].Value = (string)dataGridView1.Rows[dr].Cells[44].Value;
ocom.CommandText = ("Insert into [Consumption] (Geo_Market,location,segment_id,Parent_store_Name,store_Name,store_Level,Sub_Sub_Segment,part_no,Part_Description,part_Type,QTY,UOM,price,Averag_Stock_Value,min_level,max_level,part_location,[CM-1],[CM-2],[CM-3],[CM-4],[CM-5],[CM-6],[CM-7],[CM-8],[CM-9],[CM-10],[CM-11],[CM-12],[RM-1],[RM-2],[RM-3],[RM-4],[RM-5],[RM-6],[RM-7],[RM-8],[RM-9],[RM-10],[RM-11],[RM-12],last_issue_date,Excess_qty,Excess_value,Slow_Move) VALUES(#Geo_Market,#location,#segment_id,#Parent_store_Name,#store_Name,#store_Level,#Sub_Sub_Segment,#part_no,#Part_Description,#part_Type,#QTY,#UOM,#price,#Averag_Stock_Value,#min_level,#max_level,#part_location,#CM-1,#CM-2,#CM-3,#CM-4,#CM-5,#CM-6,#CM-7,#CM-8,#CM-9,#CM-10,#CM-11,#CM-12,#RM-1,#RM-2,#RM-3,#RM-4,#RM-5,#RM-6,#RM-7,#RM-8,#RM-9,#RM-10,#RM-11,#RM-12,#last_issue_date,#Excess_qty,#Excess_value,#Slow_Move)");
ocom.ExecuteNonQuery();
}
ocon.Close();
MessageBox.Show("Your Report Has creat And Exported To Excel");
}
Can you try changing the the comum names "CM-1" to something like "CM_1"?
I have the following code:
private void Timer1Tick(object sender, EventArgs e)
{
timer_ScanTimer.Enabled = false;
var psc = new ParseScannedCheckNumbers();
if (psc.ParseCheck(_checkData))
{
label_Status.Text = #"Scan Next Check";
var ct = checkTrans.IndividualCheck.NewIndividualCheckRow();
ct.Date = DateTime.Now.ToShortDateString();
var bracct = GetBranchAccountNumber(psc.BankAccountNumber);
if (bracct.Trim().Length == 7)
{
ct.Branch = bracct.Substring(0, 2);
ct.AccountNumber = bracct.Substring(2, 5);
ct.NameOnCheck = GetAccountName(ct.Branch + ct.AccountNumber);
ct.AccountBalance = GetAccountBalance(ct.Branch + ct.AccountNumber);
}
else
{
ct.Branch = Configuration.Branch;
ct.AccountNumber = string.Empty;
ct.NameOnCheck = string.Empty;
ct.AccountBalance = 0;
}
ct.CheckAmount = 0;
ct.BankRoutingNumber = psc.BankRoutingNumber;
ct.BankAccountNumber = psc.BankAccountNumber;
ct.CheckNumber = psc.CheckNumber;
ct.Status = "Entered";
checkTrans.IndividualCheck.Rows.Add(ct);
}
else
{
label_Status.Text = Resources.ScanCheck_ScanFailed;
}
_checkData = string.Empty;
var rs = new RegistrySettings();
if (!rs.ScanChecksContinuous)
{
StopScanning();
label_Status.Text = Resources.ScanCheck_Success;
EditLastRowEntered();
}
label_ChecksScanned.Text = (dgv_Checks.RowCount - 1).ToString();
}
When the timer goes off, I verified that I have received all of the data, then I add it to the dataset. It's being added to the dataset without issue, it's just being seen on the datagridview every time. Sometimes it works, most time it doesn't.
How do I get the datagridview to update when changes are done to the dataset? Am I doing something wrong in the above code?
Thanks! (again)
If you created the dataset and attached it to the DataGridView using the Visual Studio Data Source Configuration Wizard, then you probably have a call to
this.somethingTableAdapter.Fill(this.yourDataSet.someDataTable);
somewhere in your code. This is what actually loads the data from the DataSet into your DataGridView. While calling this method again might not be the 'proper' way to refresh your DGV, it did the job for me.