|
Hello,
I need to send selected items from the ListBox to the database field "keyrings" of datatype varbinary(128),
thelogic i used is to get the selected items from the Listbox and set the byte[] to 1 for the sected item,
//Keyrings
byte[] aGroup = new byte[1024];
string hexString;
for (int index = 0; index < SecurityGroups.Items.Count; index++)
{
if (SecurityGroups.Items[index].Selected)
aGroup[index] = 1;
}
I converted those byte[] to hexstring
hexString = ToString(aGroup);
and then send the value to the database
xmlelem = xmldoc.CreateElement("", "ATTRIBUTE", "");
atttribute = xmldoc.CreateAttribute("NAME");
atttribute.Value = "KeyRings";
xmlelem.SetAttributeNode(atttribute);
xmltext = xmldoc.CreateTextNode(hexString);
xmlelem.AppendChild(xmltext);
xmlelem4.AppendChild(xmlelem);
public static string ToString(byte[] bytes)
{
string hexString = "";
try
{
StringBuilder temp = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
temp.Append(bytes[i].ToString("X2"));
}
hexString = temp.ToString();
}
catch (Exception)
{
}
return hexString;
}
My aGroup array shows first 3 items selected as {1,1,1,0.0.0.0...,
I am having a problem in conversion from bytes to hexstring here...with the first 3 item selected in the listbox, i should get
0700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
instead i am getting 01010100000000000000....
Is there any problem with my conversion, Please suggest.
|
|
|
|
|
Hi,
you did a binary string (only 0 and 1 can be present), not a hex string.
And it was too long.
You may try something along these lines:
int count=SecurityGroups.Items.Count;
byte[] aGroup = new byte[(count+7)/8];
for (int index = 0; index < count; index++) {
if (SecurityGroups.Items[index].Selected)
aGroup[index/8] |= 1<<(index%8);
}
if all items were selected, this would or 1 to aGroup[0], then 2 to aGroup[0], then 4,
etc.; then 1 to aGroup[1] and so on, as you probably want.
|
|
|
|
|
Thanks Luc,
but when i run this piece of code.,
i am getting this error
Error 1 Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)
Is there a way to overcome?
|
|
|
|
|
Sure, this should fix it:
aGroup[index/8] |= (byte)(1<<(index%8));
|
|
|
|
|
Again i am runing into problems.,
I am having difficulties in filling the byte array from the selected items in the listbox,
byte[] aGroup = new byte[1024];
string strKeyRingResXML = "";
string strSecurity = "<security>" + key + "";
string strKeyRingReqXML = "<iacdevrequest>" + strSecurity +
"<requestoperations><dump><options><onlinemode><object id="\""" +
="" stridhi="" +="" "."="" stridlo="" "\"="">";
strKeyRingResXML = ACDev.ProcessRequest(strKeyRingReqXML);
xmlDoc.LoadXml(strKeyRingResXML);
string strAttributesPath = "IACDEVRESPONSE/RESPONSEOPERATIONS/DUMP/OBJECT/ATTRIBUTE[@NAME='KeyRings']";
XmlNode keyringNode = xmlDoc.SelectSingleNode(strAttributesPath);
string keyring = keyringNode.InnerText;
aGroup = GetBytes(keyring);
aGroup contains 100 groups
Here comes the trouble,
I have a list box which filters for the unassignable groups(50-100) for this particular server but my database contains 1000 groups so that the user can see the other 50 or even 100 groups in someother sever.
I need to make changes to the byte array for only those items(from the 50 say i select 5 groups and deselect 2 groups),
for (int index = 0; index < count; index++)
{
if (SecurityGroups.Items[index].Selected)
I need to get the value set for that particular index in the byte array
i tried doing a
aGroup[SecurityGroups.Items[index].Value] = 1;
else
aGroup[SecurityGroups.Items[index].Value] = 0;
but this does not work
}
Can someone please suggest how to go about?
|
|
|
|
|
Hello All,
I have a pdf document that I need to dynamically fill out per peron. It's just a simple 100 entry form that I want to beable to populate and save to pdf from my app. I've done a little searching around and I've seen some various tools and libraries for doing this kind of stuff. I was curious if anyone had any suggestions for a library that I could include in my app that makes it easy to populate existing pdfs with information.
Thanks for the suggestions in advance,
Ryan
|
|
|
|
|
I did a brief search of CP articles and didn't see anything...
Is it possible to get the handle to a differet process/program running? I want to try to make a program that changes programs' opacity, and I thought I'd start by trying to use the two lines:
Form f = Form.FromHandle([some app's handle]);
f.Opacity = 0.5;
I know it looks too easy to work right, and I know it sounds weird, but I want to try it anyway.
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
In your help files look up "Process". You can get a list of running processes that way. And if you already know the name of the process you can also get a list of only those processes with the specified name. From there you can get the process handle and so on.
Phil
|
|
|
|
|
Awesome, thanks!
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
how to code a administrator login page using C#.net and ASP.net 1.1
|
|
|
|
|
Hey have a Look at this article, this will help you
Get It[^]
Regards,
Satips.
|
|
|
|
|
Same way you would code a user login page.
only two letters away from being an asset
|
|
|
|
|
Hello,
I have a listbox, i need to make multiple selection and save those selectionindex to an array,
meaning if i select 3 and the 5th item from the listbox, i should have my array with the 3rd and 5th element 1, rest zero's can someone help me please to get the selection and copy it to the array?
|
|
|
|
|
If you are using .net 2.0 there is a new method called GetSelectedIndices which returns an array of int of the indexes.
public virtual int[] GetSelectedIndices ()
If you are using .net 1.1 you will need to loop through the indexes in your listbox and call listbox.GetSelected(index) passing in your index. If the method returns true the item is selected.
Hope that helps.
Ben
|
|
|
|
|
Thanks Ben
I did this,
byte[] aGroup = new byte[1024];
string hexString;
for (int index = 0; index < SecurityGroups.Items.Count; index++)
{
if (SecurityGroups.Items[index].Selected)
aGroup[index] = 1;
}
|
|
|
|
|
Hi!.. i´m new in that tools C#, and i don´t know i can see and modify my controls on the groupbox. i need a simple example or show what is the functionality, please.
thank, you. i see you soon.
|
|
|
|
|
When you add controls to a group box through the GUI interface for form building, the controls are accessable directly from anywhere in your form class. Just use the control names. If for some strange reason you need to, you can also use the group box's Controls property to get at them as well, though that's usually only used in special situations.
|
|
|
|
|
ok, i understood you, ok, only with the control's name i can have access, thank you, and if i want to know how many controls i have in the form, how can i do?.. with what method?.. thank you again..
|
|
|
|
|
int ctrlCount = groupBox1.Controls.Count;
|
|
|
|
|
thank you, Bonesoft.
|
|
|
|
|
Can i get the row number of one record from a DataTable, after searching it with it's find() method?
Thank you
Joaquim
|
|
|
|
|
|
No, this example does not work, because what you get is the record position in the DataView, that is not always the same as the record position in the datatable:
Example - a table with 4 records:
0) "9999"
1) "8888"
2) "6666"
3) "5555"
After you sort it at the DataView, it became:
0) "5555"
1) "6666"
2) "8888"
3) "9999"
And if i search the value "9999" the index should be 3, but i want the index 0 (that's the real index at the DataTable).
I need this index for positioning in the DataGrid.
Thank you anyway.
P.S. i'm not a Englis speaker, can you explain to me your last statement: 'only two letters away from being an asset', i don't know if i got it right.
|
|
|
|
|
joaquimc wrote: After you sort it
The don't sort it
only two letters away from being an asset
|
|
|
|
|
I have a web service listener that has a function that generates an XML file.
For some reason, it cannot get past the line of code below with the asterix
string xmlFilename = string.Format ("C:\\{0}.xml", m_Tag);
XmlTextWriter writer = null;
writer = new XmlTextWriter(xmlFilename,System.Text.Encoding.UTF8);*****************************
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument ();
This code works fine on my form application. Is there something i am missing.
Any input is appreciated.
Thanks,
Colin
|
|
|
|