Jump to content
Xtreme .Net Talk

catlook

Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by catlook

  1. I'm working with a windows foem application. I have a dataset that was returned from a webservice. The third column ("Permanent") contains a bool. When i bind the data to a datagridview, that coulmn shows up as a series of checked checkboxes (since all the rows happened to have "true" for that value). What I want to do is modify the dataset, before binding it to the grid, to display the word "Permanent" if the bool is true and "Temporary" is the bool is false. I've gotten the code the point where I recognise whether it's true or false, but, because the column expects a bool, I can't put in the appropriate string. Any suggestions? private void btnGetAccounts_Click(object sender, EventArgs e) { BindingSource bs = new BindingSource(); dsAccounts = new DataSet(); dsAccounts = myAccount.List(nSessionID, out nError, out sErrorMsg); if (dsAccounts != null && dsAccounts.Tables.Count > 0) { //modify datadisplay for (int i = 0; i < 10; i++) { if ((bool)dsAccounts.Tables[0].Rows[i][2] == true) { dsAccounts.Tables[0].Rows[i][2] = "Permanent"; } } bs.DataSource = dsAccounts; bs.DataMember = dsAccounts.Tables[0].TableName; dgvAccounts.DataSource = bs; } } The error I get is: "String was not recognised as valid Boolean. Couldn't store "Permanent" in Permanent column. Expected type is Boolean." It has been suggested that I use the RowDataBound event, but, sa far as I know, that only applies to ASP. That event doesn't seem to be available for DataGridViews in windows forms applications.
  2. I meant to say I found WriteContentTo and Write functions. I was looking at WriteContentTo, and maybe that's the right direction. ONly, does this mean I have to reopen the document as a FileStream, use that to instantiate a XmlTextWriter and then rewrite each element? Or how does it know to just add the one at the end? Ok, I'll sit quiet and wait now. Thanks for your assstance!
  3. Great notes!! so i now have filled in the missing snippet with : node = doc.SelectSingleNode("/SrvConfig/Facility"); if (node == null) { XmlDocumentFragment myFrag = doc.CreateDocumentFragment(); myFrag.InnerXml = "<Facility>MFG</Facility>"; XmlNode parentNode; parentNode = doc.SelectSingleNode("/SrvConfig"); parentNode.AppendChild(myFrag); } It compiles and runs without error, however the xml file doesn't contain the added node. So, I must need a write or something. I found XmlDocument Write and WriteTo functions but wasn't sure if either applied. So, how do I save my painstakingly added element?
  4. My xml layout has changed since going into production. So, i need to read the file and, if the Facility element is missing, add it in. Old xml: <SrvConfig> <HostAddress>dev123.home.com</HostAddress> <WhsNumber>03</WhsNumber> <SrvPath>/appl/03/wt4090/</SrvPath> </SrvConfig> Desired xml: <SrvConfig> <HostAddress>dev123.home.com</HostAddress> <WhsNumber>03</WhsNumber> <SrvPath>/appl/03/wt4090/</SrvPath> <Facility>MFG</Facility> </SrvConfig> So my code to read it: XmlNode node; XmlDocument doc = new XmlDocument(); //open xml file doc.Load(srvCfgPathAndName); //find element of interest node = doc.SelectSingleNode("/SrvConfig/HostAddress"); _currServerIP = node.InnerText; node = doc.SelectSingleNode("/SrvConfig/WhsNumber"); _currWhs = node.InnerText; node = doc.SelectSingleNode("/SrvConfig/SrvPath"); _currPath = node.InnerText; //since Facility wasn't part of original design we //may need to add it for existing devices node = doc.SelectSingleNode("/SrvConfig/Facility"); if (node == null) { //somehow insert it and write it back out } Can someone helpme out with the insert and write bit? Thanks!
×
×
  • Create New...