Hi,
I've an xamdatagrid with the allowaddnew property set to true. It works fine when the grid is populated. I'm able to add a new record by clicking on an empty record, but when i bind an empty source to the datagrid it doesn't allow me to add any record at all.
Is there any solution or workaround to allow adding new records even when the xamdatagrid has an empty source?
Hello,
Can you please give more information about your DataSource:
What is your empty data source? Is it a collection (which one) or DataSet?
What type is your data? If custom underlying class - should have parameterless constructor.
Alex.
Hi Alex,
The data source can be a DataSet or a XmlNodeList.
Regarding the data type, only strings for now.
Well, that is interesting regarding the DataSet.
I have tested this with an empty data set and it works as expected. I am able to add new records.
DataSet dataSet = new DataSet();DataTable dt = new DataTable();dt.Columns.Add(new DataColumn("ID"){ DataType=typeof(int)});dt.Columns.Add(new DataColumn("FName"){ DataType=typeof(string)}); dt.Columns.Add(new DataColumn("LName"){ DataType=typeof(string)});dataSet.Tables.Add(dt);xamDataGrid1.DataSource = dataSet.Tables[0].DefaultView;
I also tested it with XML provider. I have placed at least one blank record and it also works.
string dbPath = @"C:\...\Quarterbacks.xml";
System.Xml.XmlReader reader = System.Xml.XmlReader.Create(dbPath);
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(reader);
DataSet ds = new DataSet();
ds.ReadXml(new System.Xml.XmlNodeReader(doc));
DataView dv = new DataView(ds.Tables[0]);
xamDataGrid1.DataSource = dv;
<QuarterBack>
<season year="2006">
<team></team>
<games></games>
<qbrate></qbrate>
<comp></comp>
<att></att>
<pct></pct>
<passingyards></passingyards>
<passingyardspergame></passingyardspergame>
<passingyardsperattempt></passingyardsperattempt>
<passingtd></passingtd>
<int></int>
<rushs></rushs>
<rushyrds></rushyrds>
<rushyardspergame></rushyardspergame>
<rushavg></rushavg>
<rushtd></rushtd>
<sack></sack>
<yardslost></yardslost>
<fum></fum>
<fuml></fuml>
</season>
Test these and if you have still problems, please attach a sample project in your next post so that we can look it in.