|
Store the Mac Address as a Int64 and then use the format specifiers on the mac address.
|
|
|
|
|
mac2 = string.Format("{0:x2}-{1:x2}-{2:x2}-{3:x2}-{4:x2}-{5:x2}",
mac1.Substring(0,2),
mac1.Substring(2,2),
mac1.Substring(4,2),
mac1.Substring(6,2),
mac1.Substring(8,2),
mac1.Substring(10,2));
or
StringBuilder mac2 = new StringBuilder();
mac2.AppendFormat("{0:x2}", mac1.Substring(0,2));
mac2.AppendFormat("{0:x2}", mac1.Substring(2,2));
mac2.AppendFormat("{0:x2}", mac1.Substring(4,2));
mac2.AppendFormat("{0:x2}", mac1.Substring(6,2));
mac2.AppendFormat("{0:x2}", mac1.Substring(8,2));
mac2.AppendFormat("{0:x2}", mac1.Substring(10,2));
or
string mac2 = "";
for (int i = 0; i < mac1.Length; i++)
{
mac2 += mac1[i];
if ((i + 1) % 2 == 0 && i < mac1.Length-1)
{
mac2 += "-";
}
}
I'm sure there are other ways, and pretty much anything you come up with can be turned into an extension method.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
OH WAIT! How about a MACAddress class? (The following is untested code)
public class MACAddress
{
const string separator = "-";
public int[] Octets = new int[6];
public string Mac
{
get
{
StringBuilder str = new StringBuilder();
for(int i = 0; i < Octets.Length; i++)
{
str.AppendFormat("{0:x2}", Octets[i]);
if (i < Octets.Length - 1)
{
str.Append(separator);
}
}
}
public MACAddress(string address)
{
if (ValidateAddress(ref address))
{
Parse(address)
}
}
private bool Validate(ref string address)
{
address = address.Replace("-", "").Replace(":", "").Replace(" ", "").ToUpper().Trim();
if (address.Length != 12)
{
throw new Exception("Invalid mac address specified. Must be exactly 12 valid alphanumeric characters");
}
string validCharacters = "0123456789ABCDEF";
var count = (from c in address
where !validCharacters.Contains(c)
select c).Count;
if (count > 0)
{
throw new Exception("Invalid MAC address specified. One or more invalid characters detected.");
}
}
private void Parse(string address)
{
for (int i = 10; i > 0; i-2)
{
address = address.Insert(i,":");
}
string[] parts = address.Split(":");
for (int i = 0; i < parts.Length; i++)
{
Int32.TryParse(parts[i], out Octets[i]);
}
}
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Way too much time on your hands; Nice answer.
|
|
|
|
|
Nice. I always implement classes or structs for custom types like this when the framework doesn't already have them.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
I have a main form for entry purposes shown in the taskbar.
After I click on the OK button it starts a class method routine opening a status form. This should not be shown in taskbar. After doing some operation this window should automatically close.
Question:
If I switch back to my application in taskbar, I would like to get shown the status form and not the main form.
What I've tried:
1. Opening status form with ShowDialog method.
+ Switching to the application shows the status form
- All following operations are halted until status form is closed
2. Set TopMost attribute
+ switching to the application shows the status form
- Status form's always on top
3. Opening status form with Show method
+ All following operations are running afterwards
- Switching to the application shows the main window
|
|
|
|
|
Try handling the main form's Activated event and activating the status form instead.
Alternatively, adjust your design so if the user's supposed to be able to keep editing on the main form, a summary of the status is available on that form (status line? a panel that appears like Visual Studio's error pane?).
|
|
|
|
|
Hi,
From your posting I think that you want to show the main form in taskbar and not the status form when it displayed. To solve this issue try setting parent property of the status form.
Hope this helps.
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
How can I do that?
That's how I currently control my forms.
frmMain- Form:
- Clicked event on a button creates object of an action class
clsUsage _clsUsage = new clsUsage();<br />
_clsUsage.CalcUsage();<br />
CalcUsage calls and closes the status form
frmStatus _frmStatus = new frmStatus();<br />
_frmStatus.Show();<br />
_frmStatus.Close();
|
|
|
|
|
Hi
try the following.
frmStatus _frmStatus = new frmStatus();
frmStatus.parent = this;
frmStatus.showInTaskbar = false;
_frmStatus.Show();
//doing some operations and modifying attributes to controls of frmStatus form
_frmStatus.Close();
hope this helps
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
Not so easy because the call of the form is in my action class.
Tried the following.
private Form parentForm;<br />
<br />
public Form ParentForm<br />
{<br />
get { return parentForm; }<br />
set { parentForm = value; }<br />
}<br />
<br />
_clsUsage.ParentForm = this;<br />
<br />
_frmStatus.Parent = ParentForm;
But this creates an ArgumentException.
|
|
|
|
|
I am using following code:
dgTrans.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dgTrans_EditingControlShowing);
private void dgTrans_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox combo = e.Control as ComboBox;
System.Diagnostics.Debug.WriteLine(dgTrans.CurrentCell.ColumnIndex + "EditControlShowing");
if (combo != null)
{
combo.SelectedIndexChanged -= new EventHandler(dgcboDocNo_SelectedIndexChanged);
combo.SelectedIndexChanged += new EventHandler(dgcboDocNo_SelectedIndexChanged);
}
}
private void dgcboDocNo_SelectedIndexChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(dgTrans.CurrentCell.ColumnIndex + "SelectedIndexChanged");
string docno = ((ComboBox)sender).Text.ToString();
DataRow[] dr = myDs.Tables["DetailDocRegister"].Select("DocNo = '" + docno + "'");
int y = dgTrans.CurrentCellAddress.Y;
dgTrans.Rows[y].Cells[1].Value = dr[0]["DocTitle"];
}
But it not work properly. the first column is combobox. second is textbox, which will show the value according to what selected in combobox column. the first time select one item in combobox, it is ok. when you continue select items in second row. one error comes out.But if you select combobox column, then click another column, then select items in another row, it works.
how to solve this problem? thanks for your help.
|
|
|
|
|
In your SelectedIndexchanged event handler you appear to be trying to get the value for the text column from the underlying DataSet. When the SelectedIndexChanged event fires the new value has not yet been propagated to the DataSet. This doesn't happen until later. Definitely after the EndEdit for the combo column fires but exactly when depends on how your dgv is set up.
This may be the cause of your problems. It is difficult to be precise as you do not state clearly what 'one error comes out' means.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
thanks for your reply, henry.
The error happens here: dgTrans.Rows[y].Cells[1].Value = dr[0]["DocTitle"]; with description "Index was outside the bounds of the array". It means no result in datarow array dr[]. how to do nothing if no result in dr[]?
|
|
|
|
|
OK.
Simply test for a valid dr before trying to do anything with it.
private void dgcboDocNo_SelectedIndexChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(dataGridView1.CurrentCell.ColumnIndex + "SelectedIndexChanged");
string docno = ((DataGridViewComboBoxEditingControl)sender).Text.ToString();
DataRow[] dr = myDs.Tables["DetailDocRegister"].Select("DocNo = '" + docno + "'");
if (dr.Length > 0)
{
int y = dataGridView1.CurrentCellAddress.Y;
dataGridView1.Rows[y].Cells[1].Value = dr[0]["DocTitle"];
}
}
Note that I have also changed your reference to string docno = ((ComboBox)sender).Text.ToString(); this is because the DataGridViewComboBoxEditingControl has properties and methods that a plain old ComboBox doesn't. One day you might need to use them so it's a good idea to get into the habit of using the proper control now. You should also do this in your EditingControlShowing handler:
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
DataGridViewComboBoxEditingControl combo = e.Control as DataGridViewComboBoxEditingControl;
System.Diagnostics.Debug.WriteLine(dataGridView1.CurrentCell.ColumnIndex + "EditControlShowing");
if (combo != null)
{
combo.SelectedIndexChanged -= new EventHandler(dgcboDocNo_SelectedIndexChanged);
combo.SelectedIndexChanged += new EventHandler(dgcboDocNo_SelectedIndexChanged);
}
}
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
It really works. thank you very much, Henry.
|
|
|
|
|
Incidentally, if you are doing a fair amount of work with the DGV you might find the following links of interest. They are for the same thing but one is in *.doc format and the other is a *.pdf.
DataGridview FAQ.doc[^]
DataGridView FAQ.pdf[^]
Sample code is available at Sample Code[^]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
How to save a folder in one location to save in a different location using c# ?
|
|
|
|
|
|
If you want to copy try
public static void CopyDirectory(string source, string destination, bool overwrite)
{
if (!Directory.Exists(destination))
Directory.CreateDirectory(destination);
DirectoryInfo dirInfo = new DirectoryInfo(source);
foreach (FileInfo fileInfo in dirInfo.GetFiles())
fileInfo.CopyTo(Path.Combine(destination, fileInfo.Name), overwrite);
foreach (DirectoryInfo subDirectoryInfo in dirInfo.GetDirectories())
CopyDirectory(subDirectoryInfo.FullName, Path.Combine(destination, subDirectoryInfo.Name), overwrite);
}
Snippet found here
"You get that on the big jobs."
|
|
|
|
|
Hi.
I know how to edit these files. I've lost a number of sources so I had to rebuild. But, I have one app that I cannot replace the resource. App is C# of course.
From Reflector: http://www.imagebam.com/image/6001d3124889081[^]
There are .baml files and even some pngs and gifs. I managed to replace pngs before but here I cannot. Why? Is it because of PinnedMemory thing?
Any help would be appreciated.
|
|
|
|
|
I had developed an application which is a desktop application and DB is Online.
What i need is a Message popup to all the clients whenever i upload a new version on net.
(Installer is online)
Source used - C#, SQL 2008, Crystal Report 11, flash
I have no idea how to start this activity.
Please help
|
|
|
|
|
|
Or have a newsletter to which people can subscribe.
|
|
|
|
|
I want to know how to define property?
|
|
|
|