|
Step through the code with your debugger to find out what is going on.
|
|
|
|
|
The PropertiesToLoad collection does not have a default value. Since you haven't specified any properties to load, it will load all properties for the entries it finds, but the PropertiesToLoad collection will remain empty.
As a result, your DataTable will contain no columns, and the GridView will not display anything.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Help Please,
Am working on a small application to create and dial vpn connection, route ip address and open windows remote application so users do not go thru these steps manually.
Everything is working well until i connect to rdp after the command connect i don't see anything in that window.
axMsRdpClient92.Server = "DOMAIN";
axMsRdpClient92.UserName = "user";
axMsRdpClient92.AdvancedSettings7.ClearTextPassword = "Pass";
axMsRdpClient92.OnConnected += (_1, _2) => { axMsRdpClient92.RemoteProgram.ServerStartProgram(@"C:\Pims2\Pims2.exe", @"pims2 oam.pms c:\couvent", @"C:\Pims2", true, "", true); };
axMsRdpClient92.AdvancedSettings7.RDPPort = 3389;
axMsRdpClient92.AdvancedSettings7.RedirectDevices = true;
axMsRdpClient92.AdvancedSettings7.RedirectPorts = true;
axMsRdpClient92.AdvancedSettings7.GrabFocusOnConnect = true;
axMsRdpClient92.AdvancedSettings7.RedirectPrinters = true;
axMsRdpClient92.Connect();
|
|
|
|
|
string username = "";
string password = "";
{
System.Diagnostics.Process.Start(@"\\"folder path"\ foldername");
}
This is my code. How should I access to server. there is username and password for the server.
Could anyone help me??
|
|
|
|
|
Pick either the forums or QA - but don't post in both.
Posting exactly the same thing in multiple places justs wastes our time and duplicates work - particularly when the question is too vague to answer in the first place!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
was thinking about my upcoming school project focused on Windows 10 universal apps and I ran into very interesting experiment : http://gregtatum.com/poems/stochasticity/1/
I want to work on something very similiar or achieve similar level of animation in universal application writen in Csharp Win2D. I have never worked with any sort of animation or 2d graphics while writing UWA.
Can somebody direct me into right way to start with this ? What are your recommendations...any particular sample codes ?
Thank you.
|
|
|
|
|
Hi everyone,
I am learning delegates at the moment. I am trying to implement a keylogger for fun (found online)! Other examples work fine, but here I am lacking experience. However it seems, the method HookFunc is never reached.
I call it in the main method with
KeyboardHook keylogger = new KeyboardHook();
Shouldnt Install() give me output in the command box in the HookFunc method?
My Code:
public enum VKeys
{
KEY_0 = 0x30,
}
public KeyboardHook()
{
Install();
}
private delegate IntPtr KeyboardHookHandler(int nCode, IntPtr wParam, IntPtr lParam);
private KeyboardHookHandler hookHandler;
public delegate void KeyboardHookCallback(VKeys key);
#region Events
public event KeyboardHookCallback KeyDown;
public event KeyboardHookCallback KeyUp;
#endregion
private IntPtr hookID = IntPtr.Zero;
public void Install()
{
hookHandler = HookFunc;
hookID = SetHook(hookHandler);
}
public void Uninstall()
{
UnhookWindowsHookEx(hookID);
}
private IntPtr SetHook(KeyboardHookHandler proc)
{
Console.WriteLine("HookID: " + hookID.ToString());
using (ProcessModule module = Process.GetCurrentProcess().MainModule)
return SetWindowsHookEx(13, proc, GetModuleHandle(module.ModuleName), 0);
}
private IntPtr HookFunc(int nCode, IntPtr wParam, IntPtr lParam)
{
Console.WriteLine("HookID 2: " + hookID.ToString());
if (nCode >= 0)
{
int iwParam = wParam.ToInt32();
if ((iwParam == WM_KEYDOWN || iwParam == WM_SYSKEYDOWN))
if (KeyDown != null)
KeyDown((VKeys)Marshal.ReadInt32(lParam));
int vkCode = Marshal.ReadInt32(lParam);
if ((iwParam == WM_KEYUP || iwParam == WM_SYSKEYUP))
if (KeyUp != null)
KeyUp((VKeys)Marshal.ReadInt32(lParam));
vkCode = Marshal.ReadInt32(lParam);
}
else
{
;
}
return CallNextHookEx(hookID, nCode, wParam, lParam);
}
|
|
|
|
|
There are several articles (with usable code) here on CodeProject on implementing "Global Hooks" in .NET. Just search. George Mamaladze's article on this is a "CodeProject Classic," having been updated many times over several years: [^].
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Hello together,
I'm trying to implement my own IFormatProvider class.
Here are two examples:
-String.Format() - works correctly as expected
-int.ToString() - doesn't work as expected!
Below is the code:
- FormatProvider for the format method:- FormatProvider für die Format-Methode:
public class FormatProviderFormat : IFormatProvider, ICustomFormatter
{
public object GetFormat(Type formatType)
{
if (formatType == typeof(ICustomFormatter))
{
return this;
}
else
{
return null;
}
}
public string Format(string format, object arg, IFormatProvider formatProvider)
{
switch (format)
{
case "A":
return "AA";
case "B":
return "BB";
default:
return "CC";
break;
}
}
}
- The call:
DateTime dt = DateTime.Now;
IFormatProvider fpFormat = new FormatProviderFormat();
Console.WriteLine(String.Format(fpFormat, "{0:A} {0:B} {0}", dt));
- The output (makes no sense, but works as expected):
AA BB CC
Now to the problem:
-Format provider for ToString():
public class FormatProviderToString: IFormatProvider, IFormattable
{
public object GetFormat(Type formatType)
{
if (formatType == typeof(IFormattable))
{
return this;
}
else
{
return null;
}
}
public string ToString(string format, IFormatProvider formatProvider)
{
switch (format)
{
case "A":
return "AA";
case "B":
return "BB";
default:
return "CC";
break;
}
}
}
- The call:
int i = 123;
IFormatProvider fpToString = new FormatProviderToString();
Console.WriteLine(i.ToString("A", fpToString) + " " + i.ToString("B", fpToString) + " " + i.ToString(fpToString));
- The output:
Exception 'format specifier which invalid."
I don't understand what I am doing wrong.
Do you have a tip, an example or a corrected version for me?
Thanks for the help.
I'm a german Speaker. I hope you understand my question.
Regards, Manfred
modified 17-Oct-15 13:52pm.
|
|
|
|
|
Hallo Manfred,
dieses ist ein englisches Forum. Du solltest deinen Post editieren, um deine Fragen zu übersetzen.
This is an English forum. To get help you should edit your post and translate your question.
|
|
|
|
|
First, this is an English speaking site. You would have easily figured that out just by looking around.
From Bing Translate:
Quote: Hello together,
I'm trying to implement your own IFormatProvider.
Here are two examples:
-String.Format() - works correctly as expected
-int. ToString() - doesn't work as expected!
Below is the code:
-FormatProvider for the format method:
Quote: The call:
Quote: The output (makes no sense, but works as expected):
Quote: Now to the problem:
-Format provider for ToString():
Quote: The output:
Exception ' format specifier which invalid. "
I don't understand what I am doing wrong.
Has a tip, an example or a corrected version me someone?
Thanks for the help. Regards, Manfred
|
|
|
|
|
I'm not sure what are you trying to achieve with this piece of code:
int i = 123;
IFormatProvider fpToString = new FormatProviderToString();
Console.WriteLine(i.ToString("A", fpToString) + " " + i.ToString("B", fpToString) + " " + i.ToString(fpToString));
What kind of output you do expect: AA BB 3 ?
I'd suggest to read this: Formatting Types in the .NET Framework[^]
|
|
|
|
|
I have a bindinglist then i store the indexes to dictianary<int, int=""> for fast access to the bindinglist.
then i have something like this
var dIndex = new Dictionary<int, int>()
now i face a problem when removing the item in the bindiglist, because the indexes stored in the dictionary doesnt correspond anymore in the bindinglist.
so my solution is to re-arrange the indexes.
Then i got this.
int id = thisObject.ID;
if(dIndex.ContainsKey(id))
{
data.RemoveAt(dIndex[id]);
_dIndex.remove(id);
foreach(var key in dIndex.keys)
{
if(dIndex[key] > id)
{
dIndex[Key]--;
}
}
}
If I am correct, rearranging the index (the value of the dictionary) using the foreach loop above could result to an O(n).
could anyone here can give me much better solution than this.
I will appreciate for any advice.
Thank you.
|
|
|
|
|
I suggest you use a direct reference to the object(s) in the Binding List for the Value field of the generic Dictionary, rather than an index to their position in a List; since what you will actually store is a pointer, this will not consume much more memory than storing an Int16, or Int32.
In my mind, that also raises the question of why use a List when you are using a Dictionary ... however, I can't see your code, and don't know in what other ways you may be using the List.
private Dictionary<int, BindingListObject> IDToBindingListObject = new Dictionary<int, BindingListObject>();
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Yes you are right, i use the dictionary as pointer to the object, I used the key as the object id and the value as the pointer to the object. I will also use the bindinglist as a datasource. For my first implementation I am aware that it has a memory penalty, and need much more work.
I got just worried about this line of code, how would it impact the performance.
foreach(var key in dIndex.keys)
{
if(dIndex[key] > id)
{
dIndex[Key]--;
}
}
I think the remove(object) method of bindinglist has already been optimized by MS.
Thank you for your suggestion, Ill try it. I think there is no way to achieve O(1) for deleting object on the bindinglist.
|
|
|
|
|
I have created X number of ComboBoxes (PartNo) dynamically, that depending on the number selected in it, it will pull/populate some textboxes with Part Information.
All boxes have been given a Key value of cboBox1, cboBox2, etc.
How can I make an event for these comboboxes?
private void cboBox1_SelectedIndexChanged(object sender, EventArgs e)
Not sure if it matters, but the comboboxes are all part of a panel (pn), so maybe it would be?
private void pn.cboBox1_SelectedIndexChanged(object sender, EventArgs e)
I hate not knowing what I don't know.
|
|
|
|
|
Get a reference to the combo box and use, e.g.
SomeComboBox.SelectedIndexChanged += SomComboBox_SelectedIndexChanged;
Where SomeComboBox is the name of your combo box reference, e.g. cboBox1.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
I suggest that in the code that creates the ComboBoxes at run-time, you wire-up the same 'SelectedIndexChanged EventHandler to each new ComboBox:
cmbx = new ComboBox();
cmbx.SelectedIndexChanged += CmBoxIndexChanged;
private void CmBoxIndexChanged(object sender, EventArgs e)
{
if (sender == null) throw new ArgumentNullException("Error in ComboBox SelectedIndexChanged");
ComboBox caller = sender as ComboBox;
switch (caller.Name)
{
case "ComboBox0":
break;
case "ComboBox1":
break;
}
}
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Sorry to not respond earlier, but your solution works perfectly.
Thanks all for your help!
|
|
|
|
|
Hi all,
If you know all the ComboBoxes are inside the panel, why not just iterate of the Panel's ComboBox controls?
foreach (ComboBox cBox in panel1.Controls)
{
cBox.SelectedIndexChanged += cBox_SelectedIndexChanged;
}
Then when any of the ComboBox's SelectedIndexChanged events fire, you capture which one it is and do what needs to be done. eg.
void cBox_SelectedIndexChanged(object sender, EventArgs e)
{
var currentComboBox = sender as ComboBox;
if (currentComboBox == null)
return;
MessageBox.Show(currentComboBox.SelectedItem.ToString());
}
Neill
|
|
|
|
|
You could also consider using anonymous functions and lambda expressions if the function that is dynamically creating the combo box is also aware of what the drop down needs to do when updated.
public void AddComboBox(ComboBox cBox, Action<int> callback)
{
cBox.SelectedIndexChanged += (s,e) => { callback(cBox.SelectedIndex); };
}
|
|
|
|
|
The downside of this approach is that you've created a non-disposable event handler with that syntax.
|
|
|
|
|
Yes, you are correct that it would leak resources. If this were a long running application than that would be a problem otherwise the flexibility gained can potentially outweight a few kb of in memory comboboxes not reclaimed by the garbage collector. Another approach would to have an IDisposable class derive from combobox and reclaim the handler in Dispose() when the dynamically created boxes are deleted from their container.
|
|
|
|
|
public void GetBackup(string strDBName)
{
if (string.IsNullOrEmpty(strDBName))
{
MessageBox.Show("Server Name & Database can not be Blank");
return;
}
else
{
string destinationPath = ConfigurationManager.AppSettings.Get("BackupDestinationPath");
BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
ServerConnection connection = new ServerConnection(ConfigurationManager.ConnectionStrings["CostAllocationEntities2"].ConnectionString);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[strDBName];
The above line Database db = sqlServer.Databases[strDBName]; is causing the below mentioned error.
Error : "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not> found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.(provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"}
Message : Failed to connect to server D>ata
Source=PC210090\\SQLEXPRESS;Initial Catalog=testdb2;Persist Secur>ity
Info=True;User ID=sa;password=password-1"}
|
|
|
|
|
The error message is pretty explicit, and even tells you what to do.
The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
So look at your connection string, and make sure that it is correct, and that the computer you are running your application on can "see" the "PC210090" PC on it's local network segment. Then check the user name and password combination is also correct.
And don't use the SA user login - it has complete access to the databases, you should be using a user with specific permissions at all times.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|