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/ |