|
Hi all,
I am working on a an application that needs to do the following:
1. Query the registry for all the keys (approx. 100) that are written by another application and
2. Displays this information on a form.
3. Write this information to a log file.
I am using Visual Studio .NET 2010 on a Win 7 machine. The limitation I have to work with is that I have to use the .NET 3.5 framework since that is what is installed with Win 7.
I have steps 1 and 3 figured out but I have a question about step 2.
What control(s) should I use to display this information? The display itself can be very simple, for example:
REGISTRY KEY VALUE
KEY 1 0
KEY 2 20
KEY 3 0x3FF
...
NOTE: The Key names will be populated in advance by the application. The Values will be populated upon each query.
Should I use several TextBoxes? This appears to be the brute force method and not very scalable.
I tried playing with a ListView but it doesn't seem like I can update only the "Value" column.
What would you suggest?
|
|
|
|
|
Presumably your data container is a List<regkeys> where regkey has 2 fields Key and Value. Then bind that list as the datasource for the datagridview.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks, Mycroft.
I could create a list of registry key names and bind that list as the datasource to the datagridview. However, when the application runs, it will have to query the registry for each of those key names and then display the values of the key in the second column.
To clarify, when the application is first opened, I will have:
NAME VALUE
Key1 (blank)
Key2 (blank)
Key3 (blank)
...
When I click on "Run", I want to see
NAME VALUE
Key1 Value1
Key2 Value2
Key3 Value3
...
Should I then put Key1, Key2, Key3, etc... in a List?
Thanks!
|
|
|
|
|
Try it, you'll find that when your app runs it should get the value from the registry, locate the record in then List<> based on the key and add the value to the field. The DGV will automatically reflect the new data in the List<>.
Once you have created the List<> and bound it to the DGV you can ignore the DGV and work with the underlying data container - the List<>
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Why don't you use a Dictionary<string,string>. Then when the form opens you can populate each key of the KeyValuePair, bind the DGV to the Dictionary, then you can populate each value as and when you need to, or it becomes available, and rebind the DGV.
Just a thought
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
Thanks Mycroft, Wayne and Bob for your very helpful replies.
So, I have this now:
<code>// In Form1.Designer.cs
private System.Windows.Forms.DataGridView dgv_static_keys;
</code>
<code>// In Form1.cs
Dictionary<string, string> dict_static_keys = new Dictionary<string, string>
{
{"Key1", "Value1"},
{"Key2", "Value2"},
{"Key3", "Value3"},
};
BindingSource bindingsource = new BindingSource();
bindingsource .DataSource = dict_static_keys;
dgv_static_keys.DataSource = bindingsource;</code>
If I were to now update the Dictionary with a new key, say
<code>
dict_static_keys.Add("Key4", "Value4");
</code>
How do I get the DataGridView to update?
I tried this
<code>dg_static_keys.DataSource = dict_static_keys.ToList();</code>
but is there a better solution?
|
|
|
|
|
That's why I suggested using a BindingList, because it updates BindingSources that are hooked to it when the list is changed. It looks like BindingSource.ResetBindings is a slightly less brute force way to refreshing the binding if you don't want to use BindingList.
|
|
|
|
|
I would use a DataGridView, bound to a BindingList<RegistryEntry>, where
class RegistryEntry {
public string Key { get; private set; }
public string Value { get; internal set; }
}
... so the data binding only works off the (public) getters and therefore the grid is read-only.
You can update extra columns in a ListView, though. Check out ListViewItem.Subitems[0][^]. A ListView in details mode or a DGV comes down to a personal preference for the appearance, for a task like this. (It is not possible to edit subitems of a list view though, so if you want the user to be able to modify values before logging then a DGV is the way to go.)
|
|
|
|
|
Hello,
Is the GSM modem programs also works with any type of modem or the modem has to be a GSM modem,
thanks in advance,
Marcial Donet
|
|
|
|
|
Your question is not specific enough.
Given that you have an application X from Vendor M, then excluding bugs the application does whatever the Vendor wants it to do.
That can include limiting what it can be used with.
So at a very minimum you would need to explicitly identify the application that you are referring to.
On the other hand you might be asking something completely different, for example how IP works with a broadband modem.
|
|
|
|
|
|
Hi,
You shuold ask Your question in the discussion of the project.
BTW: Some mobile provider used to have SMS services where you dial in with a normal modem to send text messages to mobile phones. Usually those services implemented the protocols TAP or UCP.
Andy
|
|
|
|
|
Hi,
I am creating a pdf document using itextsharp and need to output the information into 2 columns. There is a normal paragraph before and after the section that contains the 2 columns. So the pages will look like. header, followed by a normal paragraph, followed by a columns section which is made up from a ordered list and then the final paragraph section. I am running into 2 issues.
1. MultiColumnText seems to take up all the second page even though there are only a few points from the list on it. This causes the final paragraph following the column section to be created on a new page. Is there a way of stopping this happening so the last paragraph sits just under the column
2. When the columns run into the second page I want to split the remaining 4 parts of the list into 2 columns so it only takes up the first half of the page. At present it only runs down one column. Anyone know a way that you can specifically split a column at a certain point to force it into 2 columns.
Below is a rough idea of the code
Paragraph topSection = new Paragraph("information about the points. blah blah blah"\n\n\n", normal);
topSection.SetAlignment("Left");
topSection.IndentationLeft = 40;
doc.Add(topSection);
MultiColumnText columns = new MultiColumnText();
columns.AddRegularColumns(72, 72 * 7.5f, 10, 2);
columns.AddElement(new Paragraph("This Agreement is made and entered into by and among the parties hereto as of the Effective Date with reference to the following facts:\n\n", normal));
columns.AddElement(new Paragraph("\nShort paragraph before adding the list\n\n", normal));
list.Add(new ListItem("lots and lots of text.\n\n", normal));
list.Add(new ListItem("lots and lots of text.\n\n", normal));
list.Add(new ListItem("lots and lots of text.\n\n", normal));
list.Add(new ListItem("lots and lots of text \n\n", normal));
list.Add(new ListItem("lots and lots of text.\n\n", normal));
list.Add(new ListItem("lots and lots of text.\n\n", normal));
list.Add(new ListItem("lots and lots of text.\n\n", normal));
list.Add(new ListItem("lots and lots of text.\n\n", normal));
list.Add(new ListItem("lots and lots of text.\n\n", normal));
list.Add(new ListItem("lots and lots of text.\n\n", normal));
list.Add(new ListItem("lots and lots of text.\n\n", normal));
columns.Alignment = Element.ALIGN_JUSTIFIED;
columns.AddElement(list2);
doc.Add(columns);
Paragraph signatures = new Paragraph("Assignor: <ASSIGNOR>", normal);
doc.Add(signatures);
|
|
|
|
|
Anyone any ideas to the above question?
I have also been experimenting and changing the layout to a table and trying to insert the column text into a cell but it doesn't appear to like that. Is it impossible to add a list in column format into a cell?
Thanks
Paul
|
|
|
|
|
I'm trying to find info on this online... couldn't find any...
I may have up to 4 of usb devices to process. I want in the method "DoProcess" would have to use readHandle and writeHandle variables.
I'm not sure if that is possible.
my example is as follows (code snippet):
file 1:
public struct BoxInfo
{
public int parentDeviceHandle;
public int readHandle;
public int writeHandle;
public int boxID;
public int mcuVersion;
public int pldVersion;
}
public class Main
{
public BoxInfo[] cbInfos = new BoxInfo[4];
test.DoProcess(cbinfos[2]);
}
----
file 2:
public struct BoxInfo
{
public int parentDeviceHandle;
public int readHandle;
public int writeHandle;
public int boxID;
public int mcuVersion;
public int pldVersion;
}
public class Test
{
public DoProcess(BoxInfo handleInfo)
{
...do something
}
}
|
|
|
|
|
If you are working in the same project then from the code example you provided you should remove the definition of BoxInfo from file2 such that there is only one struct BoxInfo defined per project.
Other than that, you've not actually posed a question: what is not working? Where are you getting stuck? What is the actual code you tried to use and what did the compiler complain about?
|
|
|
|
|
They are on different project. Both files are part of their own dlls.
The error that the compiler (for file 1) is "Argument 3: cannot convert from 'USB_Comm.BoxInfo' to 'HID_API_Library.BoxInfo'
USB_Comm is namespace for file 1.
HID_API_Library is namespace for file 2.
|
|
|
|
|
In that case, in USB_Comm don't declare your own BoxInfo (again). Instead, use HID_API_Library.BoxInfo.
You can add a #using HID_API_Library.BoxInfo directive to the top of your file to be able to reference BoxInfo directly, without having to specify the namespace all the time.
Like the other poster said: the two types, though structurally the same, are technically not the same type.
|
|
|
|
|
Two "structurally equal but separately declared structs" are not the same type.
So, declare that struct only once. Or, since you only need to use a couple of ints from the struct, you could pass those instead of the struct.
|
|
|
|
|
I'm trying to copy a file to a destination path (for example \newserver\destinationFolder), that can be in another domain or using a different username/password than the current user. How can I specify these new network credentials before doing the File.Copy(...) ?
pls guide me a way to copy file onto remote server of different domain with credentials..
Thanks inadvance... .
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
|
Thanks Mario for the reply..
But i want to achieve this in windows plotform not through web.
i should be able to transfer files once i know remote server's username,password and domain..
pls help me in this regard
No Defeat Is Final Until You Stop Trying!.......
modified on Thursday, June 23, 2011 1:24 AM
|
|
|
|
|
I am having a problem where when my c sharp program opens and closes excel, it leaves a reference to Excel.exe in the task manager running after I call the program to close in my code. After searching, I found the following information, but I need help implementing it into this method.
The link says that an com object with more than 1 child method per variable assignment gives the garbage collector problems. Is anyone able to rewrite the code (or at least get me started) below to have more variables and only 1 child method per variable?
Thanks for reading!
http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects-in-c[^]
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
public string dateRan = "";
public string timeRan = "";
public string userRan = "";
private void writeExcel(string data, int row, int column, bool createSheet, bool closeSheet, bool carriageReturn)
{
if (createSheet == true)
{
dateRan = loggingClass.returnDate(false, true);
timeRan = loggingClass.returnTime(false, false, true);
userRan = System.Environment.UserName;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(Missing.Value);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Cells[2, 1] = "User:";
xlWorkSheet.Cells[2, 2] = System.Environment.UserName;
xlWorkSheet.Cells[3, 1] = "Date ran:";
xlWorkSheet.Cells[3, 2] = dateRan;
xlWorkSheet.Cells[4, 1] = "Time ran:";
xlWorkSheet.Cells[4, 2] = timeRan;
}
else
{
if (data == "pass")
{
xlWorkSheet.get_Range("A" + row, "Z" + row).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Green);
}
if (data == "fail")
{
xlWorkSheet.get_Range("A" + row, "Z" + row).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
}
if (data == "manual")
{
xlWorkSheet.get_Range("A" + row, "Z" + row).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
}
xlWorkSheet.Cells[row, column] = data;
xlApp.Visible = true;
if (closeSheet == true)
{
xlWorkSheet.Application.ActiveWindow.SplitRow = 1;
xlWorkSheet.Application.ActiveWindow.FreezePanes = true;
xlWorkSheet.get_Range("A1", "Z1").Font.Bold = true;
xlWorkSheet.Columns.AutoFit();
xlWorkSheet.Rows.AutoFit();
xlWorkBook.SaveAs(@"c:\temp\log_" + dateRan.Replace("/", "-") + "__" + timeRan.Replace(":", ".") + ".xls", Excel.XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
xlWorkBook.Close(true, Missing.Value, Missing.Value);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
}
}
|
|
|
|
|
You need to store the range objects you create in a place you can clean them up. I think calling into Cells[..] is fine.
|
|
|
|
|
Thank you Bob.
I believe I have it working successfully now, but I discovered our servers don't have office on them, so I am now looking for another solution ... maybe epplus, I don't know?
|
|
|
|
|