Hi, here I have created the datatable dt,and attached to datasource i.e ultraGrid1.datasource =dt so,i dont have any dadadapter or dataset,so how can i save the data in the ultragrid drag and droped rows on the button click event.
I think the user is asking how to save the data after a drag and drop operation which is between rows and results in a reordering of the rows.
example: Row 1 becomes row 3.
The example you provided is for saving data between cells.
From what I seen, row movement uses something like UltraGrid1.Rows.Move(aRow, dropIndex).
But when this is written as in myNewDataTable = Ctype(UltraGrid1.DataSource, datatable) you can see edits to cells but the row index has not change. Row 1 is at position 1 in the datatable and so on.
I think (like to be wrong) the solution is to iterate through the grid and convert each ultragridrow to a datarow and save it to a datatable. Then save that to what you want.
JL
Hello,
Thank you for your feedback.
I have checked my solution and it seems to work just fine. Please follow these steps in order to check if it is work in your environment:
1. Download my sample solution I have posted in my post from 20th of November. Here is the link for this download http://es.infragistics.com/community/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.46.18.21/CAS_2D00_147384_2D00_S7N5N2.zip
2. Extract the solution and open it in Visual Studio.
3. Build the solution.
4. In solution Bin\Debug folder you will find UltraGridSaveToChanges.exe file. Start this file, drag and drop some cells in the grid and then click Save Data To XML button.
5. Close the application and start it again. It will load the grid as it was before you closed it.
Please find attached a short clip showing the application behavior on my machine. Please let me know if application works in your environment in this way.
Regarding constants DataAsXML and DataSchemaAsXML these are names I have used to create or load in exist the XML files representing the data table.
These two files are created when you click Save Data To XML button. When you start the application for the first time it is check if such files exist. If so the application loads the data table form the files and if not it creates new data table. This is where this check is made:
if (File.Exists(DataAsXML))
{
DataTable dataTable = new DataTable();
dataTable.ReadXmlSchema(DataSchemaAsXML);
dataTable.ReadXml(DataAsXML);
ultraGrid.DataSource = dataTable;
}
else
ultraGrid.DataSource = this.CreateDataTable();
Please let me know if you have any further questions.
hi,I have tried with that code,but it does not workthere is no drag and drop between rows and data save back to xml file.and one more thing i could not get is private const string DataAsXML = "data.xml"; private const string DataSchemaAsXML = "dataSchema.xml";there should exist data.xml file and dataschema.xml file??
Thanks in advance
Hi,
Please let me know if you need my further assistance on this matter.
Thank you for using Infragistics Components.
You are on the right way. When you set data source of the grid to a data table this will cause the grid to synchronously load the data source. More about DataSource property you may find by following the next link http://help.infragistics.com/Doc/WinForms/current/CLR4.0/?page=Infragistics4.Win.UltraWinGrid.v14.2~Infragistics.Win.UltraWinGrid.UltraGridBase~DataSource.html
After the grid is bound to the data table every change made in the grid will be populated in the data table. If at this point you close your application all the changes will be lost as you did not save them in the back to the data source (your DataBase). In order to save your changes you need some kind of back end storage as database, XML file and etc. After you set up your back end data storage you should save your data from the updated DataTable object back to the database. Final step is when you start your application to check if you have data in your data storage. If so you need to load data from the data storage.
Please let me know what your back end data storage is. What I saw in your code snippet is you did not save your data to any type of back end storage, nor you tried to load from one.
Waiting for your feedback.