Cardview Columns using Devexpress - c#

created a few seconds ago
Hi,
I am creating a web page in asp.net based on data from a database. This should result in a number of tab pages with card views on each tab with 5 columns and a maximum of 20 rows. The tab pages are working, the rows are working but the columns will not change from the default 3 columns.
I have tried setting the columnCount property at different stages, post and pre databinding. This getting frustrating.
I am having problems with setting a card views column count programmatically. I am setting it, have tried to set it in different places but it always goes to the default 3 columns :(
I am using C# in Visual studio 2017.
Here is the code I am using:
SqlDataSource sds = new SqlDataSource();
public string fName;
protected void Page_Load(object sender, EventArgs e)
{
string fid = Request.QueryString["FID"];
sds.ConnectionString = ConfigurationManager.ConnectionStrings["DataBaseConnection"].ToString();
sds.SelectCommand = "select name from [flashboard] where flashboardid = " + fid;
DataView fDet = (DataView)sds.Select(DataSourceSelectArguments.Empty);
fName = fDet.Table.Rows[0]["name"].ToString();
TitleLink.InnerHtml = fName;
sds.SelectCommand = "SELECT flashboardtabid, name FROM [FlashboardTab] WHERE flashboardid = " + fid+" order by SeqNo";
DataView fTab = (DataView)sds.Select(DataSourceSelectArguments.Empty);
TabPage tabDet;
ASPxPageControl tpc = ASPxPageControl1;
ASPxCardView cardGrp;
CardViewTextColumn cName;
CardViewHyperLinkColumn cEvidence;
foreach (DataRow tab in fTab.Table.Rows)
{
tabDet = new TabPage();
tabDet.Text = tab["name"].ToString();
tabDet.Name = "Tab"+tab["flashboardtabid"].ToString();
tabDet.ActiveTabStyle.Width = Unit.Percentage( 80);
cardGrp = new ASPxCardView();
cardGrp.ID = "CardGroup" + tab["flashboardtabid"].ToString() ;
tabDet.Controls.Add(cardGrp);
tpc.TabPages.Add(tabDet);
cardGrp.AutoGenerateColumns = false;
ASPxCardViewPagerSettings cvps = new ASPxCardViewPagerSettings(cardGrp);
cardGrp.EnableTheming = true;
cardGrp.Theme = "SoftOrange";
cvps.Visible = false;
cvps.SettingsTableLayout.ColumnCount = 5;
cvps.SettingsTableLayout.RowsPerPage = 20;
cardGrp.DataSource = GetData("SELECT cardid, Description, EvidencePage, SmartViewid FROM [flashboardcard] WHERE flashboardtabid = "+tab["flashboardtabid"] + " order by SeqNo");
cardGrp.Attributes.Add("Width", "80%");
cardGrp.Attributes.Add("style", "margin:auto");
cName = new CardViewTextColumn();
cName.Name = "Description";
cName.FieldName = "Description";
cEvidence = new CardViewHyperLinkColumn();
cEvidence.Name = "EvidencePage";
cEvidence.FieldName = "EvidencePage";
cEvidence.PropertiesHyperLinkEdit.Text = "Evidence";
cardGrp.Columns.Add(cName);
cardGrp.Columns.Add(cEvidence);
var layoutitem1 = new CardViewColumnLayoutItem(); // cardGrp.CardLayoutProperties.FindColumnItem("EvidencePage");
layoutitem1.ColumnName = "EvidencePage";
layoutitem1.ShowCaption = DevExpress.Utils.DefaultBoolean.False;
layoutitem1.HorizontalAlign = FormLayoutHorizontalAlign.Center;
var layoutitem2 = new CardViewColumnLayoutItem();
layoutitem2.ColumnName = "Description";
layoutitem2.ShowCaption = DevExpress.Utils.DefaultBoolean.False;
layoutitem2.HorizontalAlign = FormLayoutHorizontalAlign.Center;
layoutitem2.ParentContainerStyle.Font.Bold = true;
layoutitem2.ParentContainerStyle.Font.Size = FontUnit.Medium;
cardGrp.CardLayoutProperties.Items.Add(layoutitem2);
cardGrp.CardLayoutProperties.Items.Add(layoutitem1);
cardGrp.DataBind();
}
}
DataView GetData(String queryString)
{
DataView ds = new DataView();
sds.SelectCommand = queryString;
ds = (DataView)sds.Select(DataSourceSelectArguments.Empty);
return ds;
}

To resolve this issue with ColumnCount, I recommend you define it directly in the control's SettingsPager.SettingsTableLayout.ColumnCount property instead of specifying it in a new ASPxCardViewPagerSettings instance:
cardGrp.SettingsPager.SettingsTableLayout.ColumnCount = 5;
cardGrp.SettingsPager.SettingsTableLayout.RowsPerPage = 20;

Related

Telerik report showing same data for all columns created dynamically

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 });
}
}

DevExpress Lookupedit Set Selected Value

I have following Grid where it populates InquiryDetails in the Win Form Load event
private void frmInquiryManagement_Load(object sender, EventArgs e)
{
InquiryService inquiry = new InquiryService();
clearGetInquiry();
DataTable dt = InfoPCMS.db.executeSelectQuery("select * from Inquiry");
gridInquiryList.DataSource = dt;
DataTable dt2 = InfoPCMS.db.executeSelectQuery("select * from Customer");
txtCustomer.Properties.DataSource = dt2;
txtCustomer.Properties.ValueMember = "Id";
txtCustomer.Properties.DisplayMember = "CustomerName";
txtCustomer.Properties.NullText = "Please Select Customer";
txtCustomer.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("CustomerName"));
txtCustomer.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Address"));
txtCustomer.Properties.ShowHeader = false;
int nextid = inquiry.getNextId();
txtInquiryNo.Text = nextid.ToString();
}
By double clicking on a row, it searches for all the details and displays in "Get Inquiries" Tab as follows, code of that is below the image
private void selectInquiry(object sender, EventArgs e)
{
btnAddInquiry.Enabled = false;
btnUpdate.Enabled = true;
txtInquiryNo.Enabled = false;
String inquiryno = gridView1.GetFocusedDataRow()["InquiryNumber"].ToString();
InquiryService inquiry = new InquiryService();
inquiry = inquiry.searchInquiry(inquiryno);
if (inquiry != null)
{
txtInquiryNo.Text = inquiry.InquiryNumber.ToString();
//txtDate.Text = inquiry.InquiryDate;
txtDate.Text = InfoPCMS.conversion.convertDate(inquiry.InquiryDate);
txtCustomer.EditValue = inquiry.CustomerID.ToString();
txtInquiryTaken.Text = inquiry.InquiryTaken;
txtInspectionDetails.Text = inquiry.InspectionDetails;
txtProblemNature.Text = inquiry.ProblemNature;
txtProblemSource.Text = inquiry.ProblemSource;
txtSiteResponsible.Text = inquiry.SiteResponsible;
txtQuotationNo.Text = inquiry.QuotationNumber.ToString();
txtFollowupDetails.Text = inquiry.FollowupDetails;
txtInspectionDone.Text = inquiry.InspectionDone;
tabInquiryManagement.SelectedTabPage = xtraTabPage2;
}
else
{
MessageBox.Show(InfoPCMS.message.GET_NO_SUCH_RECORD_INFORMATION(), "Information");
}
}
First time you search it works fine, But after when you clear all the fields and the page and try another record it will give all the records but the Lookupedit value to its null state as follows,
private void clearGetInquiry() {
txtInquiryNo.Text = "";
txtDate.Text = "";
txtCustomer.EditValue = null;
txtInquiryTaken.Text = "";
txtInspectionDetails.Text = "";
txtProblemNature.Text = "";
txtProblemSource.Text = "";
txtSiteResponsible.Text = "";
txtQuotationNo.Text = "";
txtFollowupDetails.Text = "";
txtInspectionDone.Text = "";
btnAddInquiry.Text = "Add Inquiry";
InquiryService inquiry = new InquiryService();
int nextid = inquiry.getNextId();
txtInquiryNo.Text = nextid.ToString();
tabInquiryManagement.SelectedTabPage = xtraTabPage1;
btnAddInquiry.Enabled = true;
btnUpdate.Enabled = false;
txtInquiryNo.Enabled = true;
}
How can I get rid of this issue? (This happens even when you do the search after going into the "Get Inquiries" Tab and come.

Cascading dropdown with Ajax

I am new to Ajax. I am implementing a cascading dropdown in a telerik RadGrid.
I am adding the dropdownList and CascadingDropDown as follows:
DropDownList droplist = new DropDownList();
droplist.ID = "DropDownListOrderTask";
droplist.AutoPostBack = true;
item["OrderTask"].Controls.Add(droplist);
CascadingDropDown ccdOrderTask = new CascadingDropDown();
ccdOrderTask.ID = "ccdOrderTask";
ccdOrderTask.Category = "OrderTask";
ccdOrderTask.TargetControlID = "DropDownListOrderTask";
ccdOrderTask.PromptText = "Select Order Task";
ccdOrderTask.LoadingText = "Loading OrderTask";
ccdOrderTask.ServiceMethod = "BindOrderTask";
ccdOrderTask.ServicePath = "ajaxservice.asmx";
TextBox txt = (TextBox)item["TaskOwner"].Controls[0];
txt.Visible = false;
droplist = new DropDownList();
droplist.ID = "DropDownListTaskOwner";
item["TaskOwner"].Controls.Add(droplist);
CascadingDropDown ccdTaskOwner = new CascadingDropDown();
ccdTaskOwner.ID = "ccdTaskOwner";
ccdTaskOwner.Category = "TaskOwner";
ccdTaskOwner.ParentControlID = "DropDownListOrderTask";
ccdTaskOwner.TargetControlID = "DropDownListTaskOwner";
ccdTaskOwner.PromptText = "Select Task Owner";
ccdTaskOwner.LoadingText = "Loading Task Owner";
ccdTaskOwner.ServiceMethod = "BindTaskOwner";
ccdTaskOwner.ServicePath = "ajaxservice.asmx";
On the PreRender I have the following:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
var ajaxManager = RadAjaxManager.GetCurrent(Page);
if(ajaxManager != null)
ajaxManager.AjaxSettings.AddAjaxSetting(this._UpdatePanel, this._RadGrid1, this._RadLoadingPanel);
}
In the ajaxservice.asmx I have the following:
[WebMethod]
public CascadingDropDownNameValue[] BindOrderTask(string knownCategoryValues, string category)
{
OrderRequestTaskTypeTable _orderRequestTaskTypeTable = new OrderRequestTaskType_List().ExecuteTypedDataTable();
List<CascadingDropDownNameValue> orderTaskDetails = new List<CascadingDropDownNameValue>();
foreach(DataRow dtRow in _orderRequestTaskTypeTable.Rows)
{
String orderTaskId = dtRow["OrderRequestTaskTypeId"].ToString();
String orderTaskName = dtRow["DescriptionTaskType"].ToString();
orderTaskDetails.Add(new CascadingDropDownNameValue(orderTaskId, orderTaskName));
}
return orderTaskDetails.ToArray();
}
The first dropDown, DropDownListOrderTask contains no values. On debugging through Firebug it says: ReferenceError: BindOrderTask is not defined
I am sure I am missing something but not sure what. Please help me.

My data will be changed when com to Excel from datagridview

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"?

C# DataGridView with DataSet display issue

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.

Categories