|
:(I have a datagrid that I populate from a dataset. When I click on a row, I can use the clicked row to access the data in that row using the dataGrid1.CurrentCell.Rownumber with the following code:
object freq = ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][1];
and all works fine. After I click on a column heading to sort the dataset, and then click in a row, the row number returned is the correct new row, but the Table is not resynced, and I get the data that was at that row in the unsorted table. The following code should fix the problem (maybe):
dataGrid1.DataBind();
but this only works in a web form. I also tried rebinding as follows, but no joy:
dataGrid1.SetDataBinding(ds, "Stations");
Can anyone help?
Thanks, Barry k4mg@arrl.net
|
|
|
|
|
Hi all,
I'm new on C# and I get quite many problems.
One of them is how to register hotkeys with C#.
I entered this line in my class declaration :
[DllImport("user32.dll")] private static extern bool RegisterHotKey(long hWnd, int id, int fsModifiers, int vk);
when I run this line whatever the letter is, it doesn't work and return me false.
bool b = RegisterHotKey(GetForegroundWindow(),100,2, 'J'); // 2 = VK_CONTROL
Please help, thanks all.
Nd.
For those who could get it working, don't forget to unregister your hotkey : bool UnregisterHotKey(long hWnd, int id);
|
|
|
|
|
Anonymous wrote:
bool b = RegisterHotKey(GetForegroundWindow(),100,2, 'J'); // 2 = VK_CONTROL
Im not sure, but that 'J' bit needs to be the VK int defined in the headers, you cant assume (int) 'J' will be the correct value.
Hope this helps
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Thanks leppie for your help, I got the value of VK_J (an example) on the web, it's 0x4A. (My C# doesn't know any constant API variable)
But it doesn't work anyway.
If you need as me the numerical equivalent as WM_TIMER or VK_UP, ... go to :
http://www.vbtt.com/tips/how_to_set_or_query_the_status_of_the_keyboard.html
Nd.
|
|
|
|
|
Hi all
How do i define structs in C# from their definitions in the header files?
I have scratched C++, but not enough.
I understand most of it except for the following few:
1. How do i get the Layout and its options?
2. What is the equivalent of DWORD, WORD, LCID, etc...
3. How do i calculate the size of the struct? sizeof()?
4. What does the follow do and how/when do i know to define it? [MarshalAs(UnmanagedType.ByValTStr, SizeConst=80)]
Sorry for the lame questions
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
1. I'm not sure what you're asking. By default, structs in C# have sequential layout. You can go to Explicit layout if you need to control offsets exactly, using the StructLayout attribute.
2. DWORD = int, WORD = short. For others, you'll need to trace through the windows headers to find out how they're defined, and translate to the appropriate type. Handles should be typed as IntPtr.
3. In general, you should rarely need it. If you care about the size after it's marshalled into the unmanaged work, use Marshal.Size() (or is is SizeOf()?)
4. It says that the following string or StringBuilder should be marshalled as an embedded TCHAR array 80 characters wide. Use this when you see something like:
TCHAR value[80];
For other questions, it usually much easier to post the API you're trying to call and what your definition is
|
|
|
|
|
|
but i couldnot get
System.Configuration.dll
System.Diagnostic.dll
how to get it ?
can any body help?
r00d0034@yahoo.com
|
|
|
|
|
You will need to reference them in your project, by default only corlib and System get referenced.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
i refrence them but error found because they are not in their exact location?
r00d0034@yahoo.com
|
|
|
|
|
imran_rafique wrote:
i refrence them but error found because they are not in their exact location?
What do u mean the exact location?
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
because how will i add their refrences if i dont have or they are not available from net framework?
what to do?
if there is an error in a program that need it?
r00d0034@yahoo.com
|
|
|
|
|
if i want to add the refrence of system.diagnostic.dll
how will i add u if i dont have the file system.diagnostic.dll ?
r00d0034@yahoo.com
|
|
|
|
|
SOrry my 1st answer was a bit misleading
both those namespaces can occur in multiple dll's. They are both in mscorlib.dll and System.dll . Look there
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
if i have the hwnd of a form how to get its child hwnd ?
if i have the only hwnd of the botton then how to click it programatically because its easy to click with its object?
and how to listen a botton for action performed on it if i have only the hwnd of it?
r00d0034@yahoo.com
|
|
|
|
|
how to programatically click a button on form?
r00d0034@yahoo.com
|
|
|
|
|
Say you have a button called btnGo you simply call btnGo_Click(sender, e); , it is important to pass the two arguments.
HTH
Nick Parker
|
|
|
|
|
Nick Parker wrote:
Say you have a button called btnGo you simply call btnGo_Click(sender, e);, it is important to pass the two arguments.
Nope, that's not correct? What if there are several event liseteners? You have to use PerformClick method.
|
|
|
|
|
Rama Krishna wrote:
Nope, that's not correct? What if there are several event liseteners? You have to use PerformClick method.
There maybe other methods to do this other than the way that I described above however the follow below does work.
private void cmdSearch_Click(object sender, System.EventArgs e)
{
if(txtSearch.Text == "")
{
MessageBox.Show("Please enter a value to search on");
}
else
{
}
}
private void txtSearch_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == 13)
{
cmdSearch_Click(sender, e);
}
}
I see that the PerformClick creates a click event, but if there are several listeners as you say you would still need a method to differentiate the target. I'm assuming this can be accomplished through either overriding the WndProc or through the usage of a delagate . What do you think, or did I misunderstand what you meant about listeners?
Nick Parker
|
|
|
|
|
We normally add Click handler's like this
cmdSearch.Click += new Eventhandler(this.cmdSearch_Click);
Now it might not be that cmdSearch_Click is the only event handlet some other class may have added it's own event handling function to the delegate chain of the Click event. If you say cmdSearch_Click it will work for one, but waht about other event handlers in the chain? Performlick does that.
|
|
|
|
|
Not trying to be a pain and curious to see what you are talking about could you show a sniplet to describe what you are talking about, just having a problem visualizing this, if it is how I think I understand it.
Nick Parker
|
|
|
|
|
Perhaps a fresh perspective is needed
When dealing with events, two things are involved. A multicast delegate (ie a delegate that when invoked runs multiple methods) and the event handlers attached to that delegate.
When one calls myButton.PerformClick() you are telling the Button to fire the Click event, this in turn invokes the multicast delegate that represents the event object. This will then run all event handlers attached to the event/delegate.
When you call myButton_Click(this, EventArgs.Empty); you are calling a method that just happens to be attached to the Click event. None of the other handlers get fired and thus the click didn't really happen to anything but that one handler.
A simple test, create a form with a button named "myButton" on it, now add the following code to the class
protected override void OnLoad(EventArgs e)
{
myButton.Click += new EventHandler(click_a);
myButton.Click += new EventHandler(click_b);
}
private void click_a(object sender, EventArgs e)
{
MessageBox.Show("In click_a");
}
private void click_b(object sender, EventArgs e)
{
MessageBox.Show("In click_b");
} Now add another button to the form and try your way of forcing a click and the PerformClick method.
Obviously you'll have to call both click_a and click_b in order to get the same effect; but what if other objects have attached themselves to the click event? You have no direct way of calling them since you don't even know who or what they are; which is why the PerformClick method was created.
Hopefully that makes it clearer for you
James
|
|
|
|
|
James T. Johnson wrote:
Hopefully that makes it clearer for you
Thanks James, it does. I would like to add that many times when you want to call a click event there is only one click event that you would want to call, not two or more(at least related when related to the same object). Why would another object attach itself (i.e. - your example with one button handling multiple events) to something that already handles an event. I guess I am not seeing the value in this ability. Thanks for the visual aid though, it did help to show Rama's point.
Nick Parker
|
|
|
|
|
Nick Parker wrote:
Why would another object attach itself (i.e. - your example with one button handling multiple events) to something that already handles an event.
It doesn't happen often, but one possiblity could be a logging application where it logs all actions taken by the user. It would have one method attached to all control's Click event so it could log the event.
Another thing to look out for would be any code the button itself performs when it is clicked. The default button doesn't do anything [that i know of], but derived classes might.
James
|
|
|
|