Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
QuestionHow to write Context menu helper class Pin
Tejas Vaishnav26-Aug-14 21:09
professionalTejas Vaishnav26-Aug-14 21:09 
AnswerRe: How to write Context menu helper class Pin
Eddy Vluggen26-Aug-14 22:27
professionalEddy Vluggen26-Aug-14 22:27 
GeneralRe: How to write Context menu helper class Pin
Rob Philpott26-Aug-14 22:38
Rob Philpott26-Aug-14 22:38 
GeneralRe: How to write Context menu helper class Pin
Tejas Vaishnav26-Aug-14 23:00
professionalTejas Vaishnav26-Aug-14 23:00 
GeneralRe: How to write Context menu helper class Pin
Eddy Vluggen27-Aug-14 0:28
professionalEddy Vluggen27-Aug-14 0:28 
AnswerRe: How to write Context menu helper class Pin
Tejas Vaishnav27-Aug-14 1:26
professionalTejas Vaishnav27-Aug-14 1:26 
GeneralRe: How to write Context menu helper class Pin
Eddy Vluggen27-Aug-14 8:12
professionalEddy Vluggen27-Aug-14 8:12 
Questionc# XML nodelist to datagrid Pin
jdpiper6526-Aug-14 11:44
jdpiper6526-Aug-14 11:44 
I have an small issue of adding an XML nodelist to a datagrid. It is as follows:
I have a few code blocks that read in the nodelist from an XML file that I was able to find in several forums starting with this one which I have tweaked to suit. I am grabbing the proper nodelist (ServiceHistory) and all works well unti I try and add custom columns etc.

public static DataTable ConvertXmlNodeListToDataTable(XmlNodeList xnl)
{
DataTable dt = new DataTable();
string strOpCode, strDescription; //set up error code vars
//String OpCode;
//String Description;

int TempColumn = 0;

foreach (XmlNode node in xnl.Item(0).ChildNodes)
{
DataColumn dc = new DataColumn(node.Name, System.Type.GetType("System.String"));
if (node.Name == "Operation") //Need to get the OpCode and Descriptions out
{
CodesDesc(node.InnerText, out strOpCode, out strDescription);

dt.Columns.Add("OpCode");
dt.Columns.Add("Description");
}
TempColumn++;

if (dt.Columns.Contains(node.Name))
{
dt.Columns.Add(dc.ColumnName = dc.ColumnName + TempColumn.ToString());
}
else
{
dt.Columns.Add(dc);
}
}
int ColumnsCount = dt.Columns.Count;
for (int i = 0; i < xnl.Count; i++)
{
DataRow dr = dt.NewRow();

for (int j = 0; j < ColumnsCount; j++)
{
dr[j] = xnl.Item(i).ChildNodes[j].InnerText;
}
dt.Rows.Add(dr);
}
return dt;
}

The CodeDesc void is used to break strings out one of the nodes(<operation>) and into 2 new data columns. I am having trouble figuring out just how to go about adding the columns I want(the OpCode and Description columns) and get the strings from the Operations.Innertext into those.

public static void CodesDesc(string OpsText, out string strOpCode, out string strDescription)
{
int Lpos = OpsText.IndexOf("*");
int Rpos = OpsText.LastIndexOf("*") +1;

strOpCode = OpsText.Substring(0, Lpos);
strDescription = OpsText.Substring(Rpos);
}

The Sample XML is as follows:
XML
<?xml version="1.0" encoding="UTF-8"?>
<api:reply xmlns:api="http://www.site.com/api" version="1.0">
  <Session>
    <Reply type="Connection">
      <ErrorMessage />
      <ErrorCode>0</ErrorCode>
    </Reply>
    <Reply group="T1G1" object="ServiceHistory" type="Get">
      <ServiceHistory>
        <RecordID>XF301274*9929</RecordID>
        <SWR>661</SWR>
        <Operation>BSRS*IBN****REPAIR RIGHT SIDE DAMAGE</Operation>
        <PartsAmount>31.20</PartsAmount>
        <LaborAmount>543.00</LaborAmount>
      </ServiceHistory>
      <ServiceHistory>
        <RecordID>XF301274*9929</RecordID>
        <SWR>661</SWR>
        <Operation>RP*IBN****REFINISH &amp; PAINT DAMAGED AREA</Operation>
        <PartsAmount>0.00</PartsAmount>
        <LaborAmount>351.00</LaborAmount>
      </ServiceHistory>
      <ServiceHistory>
        <RecordID>XF301274*9929</RecordID>
        <SWR>661</SWR>
        <Operation>PM*IPM****PAINT &amp; MATERIAL</Operation>
        <PartsAmount>0.00</PartsAmount>
        <LaborAmount>198.90</LaborAmount>
      </ServiceHistory>
      <ErrorMessage />
      <ErrorCode>0</ErrorCode>
    </Reply>
  </Session>
</api:reply>


Any help is greatly appreciated...
AnswerRe: c# XML nodelist to datagrid Pin
Bernhard Hiller26-Aug-14 20:55
Bernhard Hiller26-Aug-14 20:55 
GeneralRe: c# XML nodelist to datagrid Pin
jdpiper6527-Aug-14 4:58
jdpiper6527-Aug-14 4:58 
Questionscraping C# Pin
jojoba2026-Aug-14 10:23
jojoba2026-Aug-14 10:23 
AnswerRe: scraping C# Pin
Dave Kreskowiak26-Aug-14 12:13
mveDave Kreskowiak26-Aug-14 12:13 
SuggestionRe: scraping C# Pin
jojoba2027-Aug-14 6:59
jojoba2027-Aug-14 6:59 
QuestionObject Reference Error Pin
Member 914293626-Aug-14 7:29
Member 914293626-Aug-14 7:29 
AnswerRe: Object Reference Error Pin
OriginalGriff26-Aug-14 8:17
mveOriginalGriff26-Aug-14 8:17 
GeneralRe: Object Reference Error Pin
Member 914293626-Aug-14 19:17
Member 914293626-Aug-14 19:17 
AnswerRe: Object Reference Error Pin
Richard Deeming26-Aug-14 9:21
mveRichard Deeming26-Aug-14 9:21 
GeneralRe: Object Reference Error Pin
Member 914293626-Aug-14 19:02
Member 914293626-Aug-14 19:02 
GeneralRe: Object Reference Error Pin
Bernhard Hiller26-Aug-14 21:05
Bernhard Hiller26-Aug-14 21:05 
QuestionSpeech recogination of specific language Pin
frech8726-Aug-14 1:16
frech8726-Aug-14 1:16 
AnswerRe: Speech recogination of specific language Pin
Pete O'Hanlon26-Aug-14 1:44
mvePete O'Hanlon26-Aug-14 1:44 
GeneralRe: Speech recogination of specific language Pin
frech8726-Aug-14 1:48
frech8726-Aug-14 1:48 
GeneralRe: Speech recogination of specific language Pin
ZurdoDev26-Aug-14 1:56
professionalZurdoDev26-Aug-14 1:56 
GeneralRe: Speech recogination of specific language Pin
GuyThiebaut26-Aug-14 3:40
professionalGuyThiebaut26-Aug-14 3:40 
GeneralRe: Speech recogination of specific language Pin
Pete O'Hanlon26-Aug-14 3:55
mvePete O'Hanlon26-Aug-14 3:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.