Click here to Skip to main content
15,913,758 members
Home / Discussions / C#
   

C#

 
GeneralRe: Reflection ! Pin
Mohammad Dayyan25-Mar-09 11:45
Mohammad Dayyan25-Mar-09 11:45 
GeneralRe: Reflection ! Pin
DaveyM6925-Mar-09 11:50
professionalDaveyM6925-Mar-09 11:50 
GeneralRe: Reflection ! Pin
Mohammad Dayyan25-Mar-09 11:53
Mohammad Dayyan25-Mar-09 11:53 
GeneralRe: Reflection ! Pin
DaveyM6925-Mar-09 12:31
professionalDaveyM6925-Mar-09 12:31 
GeneralRe: Reflection ! Pin
Luc Pattyn25-Mar-09 13:31
sitebuilderLuc Pattyn25-Mar-09 13:31 
QuestionDepedencies Pin
CodingYoshi25-Mar-09 11:04
CodingYoshi25-Mar-09 11:04 
AnswerRe: Depedencies Pin
Colin Angus Mackay25-Mar-09 14:43
Colin Angus Mackay25-Mar-09 14:43 
QuestionRemoving a duplicate row C# and WMI Pin
Buck_Murdock25-Mar-09 10:57
Buck_Murdock25-Mar-09 10:57 
I've built an InfoPath form that queries WMI data and displays it in the form so that we can submit the info to a SharePoint list.

I'm putting on the final touches and am having problems with one small section. When i query the RAM, i have it display the information into a repeating table. The problem is when i create the repeating table for some reason it duplicates the first row. I found an article on how to remove the first row (http://www.bizsupportonline.net/infopath2007/programmatically-delete-first-row-repeating-table-infopath.htm)

I use this same bit of code to remove the first row from another section and it works just fine, but for some reason when i do this very same thing it deletes the first 2 rows. I can't figure out why it works fine in one section but not in the other section, i copied and pasted the same bit of code so it should work the same. If someone could help me figure out what's going on here i'd appreciate it.

code sample:
using Microsoft.Office.InfoPath;

using System;

using System.Xml;

using System.Xml.XPath;

using System.Management;

using System.Net.NetworkInformation;

namespace Inventory_Rev1

{

public partial class FormCode

{

// Member variables are not supported in browser-enabled forms.

// Instead, write and read these values from the FormState

// dictionary using code such as the following:

//

// private object _memberVariable

// {

// get

// {

// return FormState["_memberVariable"];

// }

// set

// {

// FormState["_memberVariable"] = value;

// }

// }

// NOTE: The following procedure is required by Microsoft Office InfoPath.

// It can be modified using Microsoft Office InfoPath.

ManagementObjectSearcher searcherMemory =

new ManagementObjectSearcher("root\\CIMV2",

"SELECT * FROM Win32_PhysicalMemory");

public void InternalStartup()

{

EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);

}

public void FormEvents_Loading(object sender, LoadingEventArgs e)

{

foreach (ManagementObject queryObj in searcherMemory.Get())

{

int counter = 1;

{

string slot = queryObj["DeviceLocator"].ToString();

string capacity = queryObj["Capacity"].ToString();

string speed = queryObj["Speed"].ToString();


// Create an XPathNavigator to walk the main data source

// of the form.

XPathNavigator xnMyForm = this.CreateNavigator();

XmlNamespaceManager ns = this.NamespaceManager;

// Set the fields in the form.

xnMyForm.SelectSingleNode("/my:myFields/my:Memory/my:Ram/my:slot", ns)

.SetValue(slot);

xnMyForm.SelectSingleNode("/my:myFields/my:Memory/my:Ram/my:capacity", ns)

.SetValue(capacity);

xnMyForm.SelectSingleNode("/my:myFields/my:Memory/my:Ram/my:speed", ns)

.SetValue(speed);


// Increment the counter

counter++;

// Add the item to the repeating table

AddItemMemory(slot, capacity, speed);



// Remove the first empty item from the repeating table

DeleteFirstEmptyItemMemory();

}

}

}

private void AddItemMemory(string slot, string capacity, string speed)

{

XmlDocument doc = new XmlDocument();

XmlNode group = doc.CreateElement("Ram",

NamespaceManager.LookupNamespace("my"));

XmlNode field = doc.CreateElement("slot",

NamespaceManager.LookupNamespace("my"));

XmlNode node = group.AppendChild(field);

node.InnerText = slot;

field = doc.CreateElement("capacity",

NamespaceManager.LookupNamespace("my"));

node = group.AppendChild(field);

node.InnerText = capacity;

field = doc.CreateElement("speed",

NamespaceManager.LookupNamespace("my"));

node = group.AppendChild(field);

node.InnerText = speed;

doc.AppendChild(group);

MainDataSource.CreateNavigator().SelectSingleNode(

"/my:myFields/my:Memory",

NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());



}

private void DeleteFirstEmptyItemMemory()

{

XPathNavigator domNav = MainDataSource.CreateNavigator();

XPathNavigator itemNav = domNav.SelectSingleNode(

"/my:myFields/my:Memory/my:Ram[1]",

NamespaceManager);

if (itemNav != null)

itemNav.DeleteSelf();

} 

}

}

QuestionAnybody here handle what happens when you unplug a USB based Serial Port? Pin
Wes Jones25-Mar-09 10:26
Wes Jones25-Mar-09 10:26 
AnswerRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Henry Minute25-Mar-09 10:52
Henry Minute25-Mar-09 10:52 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Wes Jones25-Mar-09 11:04
Wes Jones25-Mar-09 11:04 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Henry Minute25-Mar-09 11:15
Henry Minute25-Mar-09 11:15 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
DaveyM6925-Mar-09 11:19
professionalDaveyM6925-Mar-09 11:19 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Luc Pattyn25-Mar-09 13:36
sitebuilderLuc Pattyn25-Mar-09 13:36 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Colin Angus Mackay25-Mar-09 14:48
Colin Angus Mackay25-Mar-09 14:48 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Wes Jones25-Mar-09 15:34
Wes Jones25-Mar-09 15:34 
AnswerRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Henry Minute25-Mar-09 11:41
Henry Minute25-Mar-09 11:41 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
DaveyM6925-Mar-09 11:43
professionalDaveyM6925-Mar-09 11:43 
QuestionStreamWriter help... Pin
VoodooInfinity25-Mar-09 10:07
VoodooInfinity25-Mar-09 10:07 
AnswerRe: StreamWriter help... Pin
BOMBONEW25-Mar-09 10:14
BOMBONEW25-Mar-09 10:14 
GeneralRe: StreamWriter help... [modified] Pin
VoodooInfinity25-Mar-09 10:23
VoodooInfinity25-Mar-09 10:23 
AnswerRe: StreamWriter help... Pin
J$25-Mar-09 10:34
J$25-Mar-09 10:34 
AnswerRe: StreamWriter help... Pin
Ian Shlasko25-Mar-09 10:34
Ian Shlasko25-Mar-09 10:34 
QuestionC# and Data Acquisition Application Pin
stancrm25-Mar-09 10:06
stancrm25-Mar-09 10:06 
JokeRe: C# and Data Acquisition Application Pin
Eddy Vluggen25-Mar-09 10:31
professionalEddy Vluggen25-Mar-09 10:31 

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.