DataGrid and XML document

J

Jussi

I load a XML document in the DataGrid:

private System.Windows.Forms.DataGrid myDataGrid = new DataGrid();
private DataSet m_myDataSet = new DataSet();

m_myDataSet.ReadXml(@"C:\...\MyDocument.xml");
myDataGrid.DataSource = m_myDataSet;

This works fine and user can edit the loaded document. The problem is that I
don't want to give possibility to change the structure of the
MyDocument.xml. User should only change data in the already existing fields.
In the DataGrid user can create for example new rows and these are saved to
the MyDocument.xml when

m_myDataSet.WriteXml(@"C:\...\MyDocument.xml");

is done and MyDocument.xml is corrupted. Is there a way to avoid this?

-JK
 
A

Arne Janning

Jussi said:
I load a XML document in the DataGrid:

private System.Windows.Forms.DataGrid myDataGrid = new DataGrid();
private DataSet m_myDataSet = new DataSet();

m_myDataSet.ReadXml(@"C:\...\MyDocument.xml");
myDataGrid.DataSource = m_myDataSet;

This works fine and user can edit the loaded document. The problem is that I
don't want to give possibility to change the structure of the
MyDocument.xml. User should only change data in the already existing fields.
In the DataGrid user can create for example new rows and these are saved to
the MyDocument.xml when

m_myDataSet.WriteXml(@"C:\...\MyDocument.xml");

is done and MyDocument.xml is corrupted. Is there a way to avoid this?

http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q653q

Cheers

Arne Janning
 
A

Ashutosh Ambekar

Hi,

Add eventhandler for event CurCellChange of the datagrid control and see if the current row value is greater thatn your data size.
If yes, then discard the change (focus back to earlier selected row/cell).

HTH,
Ashutosh


Hi,

When I read from a XML Document and assign -

DataSet.ReadXml(@"C:\Abc.Xml",XmlReadMode.Auto);
DataGrid.DataSource = DataSet;

I get the DataGrid filled, but the data is not filled in the datagrid. It
shows Table Name as a link, on clicking of which the grid is filled. Even
the DataGrid.Expand(-1) do not expand the rows.

Is there any way for this?

Thanks

Thejus
 
A

Ashutosh Ambekar

Hi,

use following statement after populating the datagrid with the dataset.
dataGrid2.NavigateTo(0,"<your table name>");

-Ashutosh



Hi,

When I read from a XML Document and assign -

DataSet.ReadXml(@"C:\Abc.Xml",XmlReadMode.Auto);
DataGrid.DataSource = DataSet;

I get the DataGrid filled, but the data is not filled in the datagrid. It
shows Table Name as a link, on clicking of which the grid is filled. Even
the DataGrid.Expand(-1) do not expand the rows.

Is there any way for this?

Thanks

Thejus
 
T

Thejus

Hi,

When I read from a XML Document and assign -

DataSet.ReadXml(@"C:\Abc.Xml",XmlReadMode.Auto);
DataGrid.DataSource = DataSet;

I get the DataGrid filled, but the data is not filled in the datagrid. It
shows Table Name as a link, on clicking of which the grid is filled. Even
the DataGrid.Expand(-1) do not expand the rows.

Is there any way for this?

Thanks

Thejus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top