HighTechTalks DotNet Forums  

Adding new rows to a XML bound datagrid.

Dotnet Framework (WinForms DataBinding) microsoft.public.dotnet.framework.windowsforms.databinding


Discuss Adding new rows to a XML bound datagrid. in the Dotnet Framework (WinForms DataBinding) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Mark Gillespie
 
Posts: n/a

Default Adding new rows to a XML bound datagrid. - 07-15-2008 , 12:41 PM






Hi, I am having some troubles with databinding. I am quite new, so it may
be a stupid thing I have done. If so, excuse me..

I have a datagrid that is bound to a XMLSchema, and that works nicely, I
can add rows correctly using he datagrid, and the XML it produces is
perfect, however I also need to programatically add data, and have the
datagrid show the updated table.

Now I figured I don't touch the datagrid itself, but add the data to the
dataset and let the binding deal with it. The problem I am having, is
it's putting it at the "wrong level" in the XML:


<MyData xmlns="http://tempuri.org/MyData.xsd">
<DataList CreatedBy="TestEditor" Version="0.3">
<Data StringAttr1="ExistingData1" BoolAttr1="true" />
<Data StringAttr1="ExistingData2" BoolAttr1="true" />
<Data StringAttr1="ExistingData3" BoolAttr1="true" />
<Data StringAttr1="ExistingData4" BoolAttr1="true" />
<Data StringAttr1="ExistingData5" BoolAttr1="true" />
</DataList>
<Data StringAttr1="AddedData1" BoolAttr1="true" />
<Data StringAttr1="AddedData2" BoolAttr1="true" />
<Data StringAttr1="AddedData3" BoolAttr1="true" />
<Data StringAttr1="AddedData4" BoolAttr1="true" />
</MyData>


The "AddedData" should be within the <DataList>tags.

My method of adding looks something like this:

public void AddSite( string theStringAttr, bool theBoolAttr )
{
int CurrentTable = m_MyDataSet.Tables.IndexOf("Data");
if (CurrentTable > 0)
{
DataRow NewRow;
NewRow = m_MyDataSet.Tables[CurrentTable].NewRow();
m_MyDataSet.Tables[CurrentTable].Rows.InsertAt( NewRow, 0
);
NewRow["StringAttr1"] = theSiteName;
NewRow["StringAttr1"] = theBoolAttr;

//Also tried this, same result..
//m_MyDataSet.Tables[CurrentTable].Rows.Add(new object[] {
theStringAttr, theBoolAttr });
}
else
{
MessageBox.Show("Can't find table", "Error");
}
}



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.