Inserting rows at a particular point in a DataTable is easy, inserting columns was a bit trickier as the DataGridView didn't update or refresh its view of the DataSource;
if (dataGridView.SelectedCells.Count > 0)
{
int selectedCellCol = dataGridView.SelectedCells[0].ColumnIndex;
DataColumn newColumn = new DataColumn();
// Set properties of the new column
workingDataSet.Tables[0].Columns.Add(newColumn);
newColumn.SetOrdinal(selectedCellCol);
this.dataGridView.DataSource = null;
this.dataGridView.DataSource = workingDataSet.Tables[0];
this.dataGridView.Refresh();
}
It seems setting the DataSource to null, followed by pointing it back at the DataTable source forced the data in the DataGridView to refresh.
Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts
Thursday, 21 October 2010
Monday, 11 October 2010
Microsoft Dynamics AX Call a Static Method from C#.Net X++
Install the .Net Business Connector is installed. If not, it can be using the AX Client Setup.
Add a reference to the Business Connector DLL "C:\Program Files\Microsoft Dynamics AX\50\Client\Bin\Microsoft.Dynamics.BusinessConnectorNet.dll"
Access the method as follows;
using Connector = Microsoft.Dynamics.BusinessConnectorNet;
Connector.Axapta axInstance;
axInstance = new Connector.Axapta();axInstance.LogonAs("Username", "Domain", null, null, null, null, "AXShortcut.axc");
returnVal = (string)ax.CallStaticClassMethod("MyAXClass", "MyAXMethod", "MyArgs");
The (string) cast of the return value could change.
Add a reference to the Business Connector DLL "C:\Program Files\Microsoft Dynamics AX\50\Client\Bin\Microsoft.Dynamics.BusinessConnectorNet.dll"
Access the method as follows;
using Connector = Microsoft.Dynamics.BusinessConnectorNet;
Connector.Axapta axInstance;
axInstance = new Connector.Axapta();axInstance.LogonAs("Username", "Domain", null, null, null, null, "AXShortcut.axc");
returnVal = (string)ax.CallStaticClassMethod("MyAXClass", "MyAXMethod", "MyArgs");
The (string) cast of the return value could change.
Friday, 8 October 2010
C#.net Read & Write XML Files
Code to Read an XML File into a DataSet;
this.workingDataSet = new DataSet();
FileStream xmlStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
workingDataSet.ReadXml(xmlStream);
xmlStream.Close();
Code to Write a DataSet to an XML file (UTF8);
FileStream xmlStream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
XmlTextWriter xmlWriter = new XmlTextWriter(xmlStream, Encoding.UTF8);workingDataSet.WriteXml(xmlWriter);
xmlStream.Close();
this.workingDataSet = new DataSet();
FileStream xmlStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
workingDataSet.ReadXml(xmlStream);
xmlStream.Close();
Code to Write a DataSet to an XML file (UTF8);
FileStream xmlStream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
XmlTextWriter xmlWriter = new XmlTextWriter(xmlStream, Encoding.UTF8);workingDataSet.WriteXml(xmlWriter);
xmlStream.Close();
Subscribe to:
Posts (Atom)