I have a datagridview, and I am populating it from a datatable which in turn retrieves it's data from a webservice query (against SalesForce cloud system).
Essentially we want to show the results of attempting to remove attachments from SalesForce cases which have been put on there by the users, currently we query a SalesForce XML webservice called case and we want to add the capability to also query a second new SalesForce object called credit case.
It has been working fine getting its data from an object called cases, and displaying them in a Windows Forms datagridview control.
Now we want to add another object (let's call it creditCases), so I have the query all setup, have added another task object with the fields and datatypes and so on.
Once the dataset is populated we set the data source of the datagridview using gvTaskCases.DataSource = dtCases;
But of course I now have a second datasource (with a different number of columns) that I want to add to the table.
If I do this with my new datatable (gvTaskCases.DataSource = dtcreditCases) how do I stop it replacing the data from the existing datatable?
CODE:
gvTaskCases.DataSource = null;
dtCases.Rows.Clear();
foreach (task_cases item in cases)
{
DataRow drCases = dtCases.NewRow();
// Then add the new row to the collection.
drCases["Case ID"] = item.c_Id;
drCases["Case Number"] = item.c_Number;
drCases["Case Topic"] = item.c_Topic;
drCases["Case SubTopic"] = item.c_Subtopic;
drCases["Account Number"] = item.c_CustomerNumber;
drCases["Additional Info"] = item.c_AdditionalInfo;
drCases["Closed Date"] = Convert.ToDateTime(item.c_ClosedDate).ToString("dd/MM/yyyy");
drCases["Attachment"] = item.c_Attachment;
drCases["Content Type"] = item.c_ContentType;
drCases["Detach Status"] = item.c_Status;
drCases["Document Type"] = item.c_DocumentType;
drCases["Imaging Directory"] = item.c_ImagingDSXDirectory;
drCases["Imaging Document"] = item.c_ImagingDocument;
dtCases.Rows.Add(drCases);
}
gvTaskCases.DataSource = dtCases;
gvTaskCases.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
gvTaskCases.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
foreach (task_creditcases item in creditCases)
{
DataRow drCases = dtCases.NewRow();
// Then add the new row to the collection.
drCases["Case ID"] = item.c_Id;
drCases["Case Number"] = item.c_Name; // SalesForece Credit Case Object CASE NUMBER;
drCases["Account Number"] = item.c_Account__c;
drCases["Closed Date"] = Convert.ToDateTime(item.c_Closed_Date__c).ToString("dd/MM/yyyy");
drCases["Attachment"] = item.c_Imaging_Document_Attached__c;
drCases["Detach Status"] = item.c_Status__c;
drCases["Document Type"] = item.c_Document_Type__c;
drCases["Imaging Directory"] = item.c_Directories__c;
drCases["Imaging Document"] = item.c_Imaging_Document;
dtCases.Rows.Add(drCases);
}
// add the new records:
// Adjust size & hide columns that aren't needed
gvTaskCases.Columns[0].Visible = false;
gvTaskCases.Columns[11].Visible = false;
gvTaskCases.Columns[12].Visible = false;
gvTaskCases.Columns[13].Visible = false;
dtcasesbut I wanted to keep them seperate if possible - Our Man in BananasDataTable, possibly you have to keep some reference to it and create a newDataTablefrom both the old and newDataTable, of course that will change the meaning ofreuse. - King King