|
I have a MainForm. In this mainform is a menulike UserControl TreeView or ListBox. When the user choses a MenuItem a ChildForm in the mainform is shown where the user can input some data. Now I would like that the UserInterface acts as follows: the user should be able to access MenuItems by Key (say ALT+X) without that the MenuControl must have the focus.
So how can I get every Keyboard Input from any form or any control?
I would like to check these inputs for special key ALT and then switch to chosen MenuPoint.
I tried with MDIContainer-Form but didn't seam to be very usefull for this problem.
Any suggestions are very welcome!
Thanks
Stefan
|
|
|
|
|
Hi,
I have a DataGrid Bound to a table. How can I update my table after a row has been selected and deleted from the grid?
I tryed the following (but it did not work):
CurrencyManager cm = (CurrencyManager)this.BindingContext[myDatagrid.DataSource, MydataGrid.DataMember];
cm.EndCurrentEdit();
cm.Refresh();
SqlDataAdapter da = new SqlDataAdapter();
da.Update(myTableBoundToTheDatagrid);
Let's say i have 1 row in my table, I delete it from the grid, I still have one row in my table, after running the code above.
Thanks for any comment,
Yann
|
|
|
|
|
The following should work
DataSet something = GetSomethingFromTheDB();
myDataGrid.DataSource = something;
//Allow deletes from the grid..
SqlDataAdapter da = new SqlDataAdapter();
da.Update(something);
|
|
|
|
|
I need to programmatically retrieve IP configuration information using the IP Helper APIs GetNetworkParams() from C#.
Everytime I call the function all I get back is a value of 87
I come from a Java background and I am unfamiliar with both structs and DLL's.
Below is my code, I would appreciate it if someonce code provide me with a working implementation or pointers to what I am doing wrong;)
The results of running the code are
UNKNOWN ERROR => 87
bufferSize => 9999999999999999999
error => 87
using System;
using System.Runtime.InteropServices;
namespace dlltest
{
public class IpHelperTest
{
public const int ERROR_BUFFER_OVERFLOW = 111;
[DllImport("IPHLPAPI.DLL")]
public static extern long GetNetworkParams(ref FIXED_INFO buf, ulong cbRequired);
public IpHelperTest()
{
ulong bufferSize = 9999999999999999999;
FIXED_INFO Info = new FIXED_INFO();
long error = GetNetworkParams(ref Info, bufferSize);
if(error == ERROR_BUFFER_OVERFLOW)
{
Console.WriteLine("BUFFER OVERFLOW => "+error);
}
else if(error == 0)
{
Console.WriteLine("GOT INFO");
}
else
{
Console.WriteLine("UNKNOWN ERROR => "+error);
}
Console.WriteLine("bufferSize => "+bufferSize);
Console.WriteLine("error => "+error);
}
[StructLayout(LayoutKind.Sequential)]
public struct IP_ADDR_STRING
{
long dwNext;
String IpAddress;
String IpMask;
long dwContext;
}
[StructLayout(LayoutKind.Sequential)]
public struct FIXED_INFO
{
String HostName;
String DomainName;
IP_ADDR_STRING CurrentDnsServer;
IP_ADDR_STRING DnsServerList;
long NodeType;
String ScopeId;
long EnableRouting;
long EnableProxy;
long EnableDns;
}
public static void Main()
{
IpHelperTest ipHelperTest = new IpHelperTest();
}
}
}
|
|
|
|
|
In an application that I am writing I am loading lots of different forms and Windows XP groups those forms, when there are too many for the Taskbar. I have set different properties of my projects but no text appears on the grouping.
Does anyone know what property I have to set to create the grouping name?
Thanks
Adam
|
|
|
|
|
I will add an event property for all my MenuItem objects. To do this, I add an IExtenderProvider derived class to my application and implement the Get, Set and CanExtend methods. This work fine except that the event property cannot be edited in the event property tab! It is also grayed in the attribute property tab! Has some body an idee how to use IExtenderProvider with events ?
<br />
using System;<br />
using System.ComponentModel;<br />
using System.Collections;<br />
using System.Diagnostics;<br />
using System.Windows.Forms;<br />
<br />
namespace MenuProperty<br />
{<br />
public interface IUpdateUI<br />
{<br />
void Enable(bool enable);<br />
void Check(bool check);<br />
}<br />
<br />
public delegate void EventUpdateUI(IUpdateUI updateUI, EventArgs e);<br />
<br />
[<br />
ProvideProperty("UpdateUI", typeof(Component)),<br />
]<br />
public class MenuUpdateUI : System.ComponentModel.Component, IExtenderProvider<br />
{<br />
Hashtable dictionaryUpdateUI = new Hashtable();<br />
<br />
public void SetUpdateUI(Component component, EventUpdateUI updateUI)<br />
{<br />
if (updateUI != null && !dictionaryUpdateUI.Contains(component))<br />
{<br />
dictionaryUpdateUI.Add(component, updateUI);<br />
MenuItem menuItem = (MenuItem)component;<br />
}<br />
}<br />
<br />
public EventUpdateUI GetUpdateUI(Component component) <br />
{<br />
if (dictionaryUpdateUI.Contains(component))<br />
return (EventUpdateUI)dictionaryUpdateUI[component];<br />
return null;<br />
}<br />
<br />
public bool CanExtend(object obj)<br />
{ <br />
return (obj is MenuItem);<br />
} <br />
}<br />
}<br />
|
|
|
|
|
Hi all,
I want to have 4 coulmns in my data grid. Three columns listing strings and the fourth column must have checkbox.
I don't have a database behind. [And from what I understand we have to specify some datasource to display results in the grid]. I do a search on certain properties in instances of my own class and I want to list the serach results in the datagrid. I can populate the search results in an array and assign the datasource of the grid to this array. But to display results as four columns I need an 1 X 4 array. But the datagrid shows runtime error saying the array is not one dimensional
Is there an easy way out ? What is the best way to display my results? Is it grid or something else ? In the case of grid, how will I assign my 1 X 4 array to the grid ?
Thanks
Smitha
Imagination is more important than knowledge.
--Albert Einstein
|
|
|
|
|
:-OHi!
Try filling it via DataTable! or simply add rows manually.
<br />
<br />
ICollection CreateDataSource() <br />
{<br />
DataTable dt = new DataTable();<br />
DataRow dr;<br />
<br />
if(Read())<br />
{<br />
for(int i=0;i<myReader.FieldCount;i++)<br />
{<br />
dt.Columns.Add(<br />
new DataColumn(<br />
myReader.GetName(i)));<br />
}<br />
<br />
do<br />
{<br />
dr = dt.NewRow();<br />
for(int i=0;i<myReader.FieldCount;i++)<br />
{<br />
dr[i] = myReader.GetValue(i);<br />
}<br />
dt.Rows.Add(dr);<br />
}while(Read());<br />
<br />
}<br />
<br />
DataView dv = new DataView(dt);<br />
<br />
return dv;<br />
} <br />
<br />
...
dg1.DataSource = CreateDataSource();<br />
dg1.DataBind();<br />
Checkbox: try itemtemplates. Edit your aspx file.
Agyklon
|
|
|
|
|
You may to create a DataTable from array and use it as a datasource. Sorry, it isn't too smart ...
Hi,
AW
|
|
|
|
|
Thanks for the help guys
Smitha
The future belongs to those who believe in the beauty of their dreams.
--Eleanor Roosevelt
|
|
|
|
|
Create a blank project, set the WindowState to minimized in the designer and in the form1_load event put this.Hide();
Now why do I get different behavior when I keep the WindowState to Normal but add this.WindowState = FormWindowState.Minimized; this.Hide();
to the form1_load event?
Aren't they the same thing?
|
|
|
|
|
I have created a MDI parent form which has a UserControl
inside.
I create two instances of the form with the UserControl as
mdi children.
I shrink them down vertically so scroll bars appear. Then
drag the scrollbars down to the bottom of the form.
Select one child form, and then select another child form,
in effect, changing focus between the two forms.
When I click on one child, then another, the contained
UserControl jumps and the scroll bar moves to reposition
the contents of the form.
I do not see this behavior if I use a label instead of a
user control.
I dont want the contents of the child form to be
repositioned when you change focus to/from a child.
Having this behavior really breaks my app; I cannot have
windows automatically moving contents after a user has
carefully positioned the windows and the scroll bars where
they want them.
How can I keep the contents of a form with a UserControl
in the same place even if the user moves around between
different MDI child windows?
I saw mention of a known bug in .NET that was described as
follows from the following link:
http://www.windowsforms.com/Forums/showpost.aspx?
tabindex=1&tabid=41&PostID=261
Case in point, killing that annoying autoscroll reset to
upper left corner on a scrollable control recieving focus.
Took me about 8 hours to work around it; the simple
override of WndProc to ignore WM_SETFOCUS seemed OK at
first, but screwed up the setting of the active control
property. If I had access to source, it would have taken
me all of 5 minutes to find the proper workaround (setting
the scroll state to manual during the WM_SETFOCUS handler)-
-
Can anyone suggest what is going on here, and perhaps give
me a start on how to fix the problem? I am not familiar
with overriding Wndproc.
|
|
|
|
|
I need to copy and send the data in a private structure from an MFC app to a .NET app. Somehow, the following does not seem to work. When I use the WM_COPYDATA windows message as indicated below, it is not being received by the WndProc on the .NET side, but when I use a private message, it is received. Unfortunately, when I use the private message, the data seems not to be copied across and I get an assertion error for null data. WM_COPY is not received on the .NET side, but when a private message is used, it is received but then Marshal.PtrToStructure asserts reporting a null value.
Using COM interop is not an option. The client thinks that COM will slow things down as the function is called thousands of times.
Does any one have a suggestion, or a better approach?
Thanks
Gaul
****************************
ON THE MFC SIDE
****************************
////////////////////////////////////////////////////////////
// Increment is called on the MFC side
/////////////////////////////////////////Increment Counter
long CTSPerfMon::Increment(int objectID, int instID)
{
_msg.nMsgID = TS_MSG_INCREMENT;
_msg.nObjectID = objectID;
_msg.nInstID = instID;
_msg.nValue = -1;
return SendMessage();
}
// Send Message across to the .NET side module
long CTSPerfMon::SendMessage()
{
// Fill the WIN32 COPYDATASTRUCT structure
_copyData.dwData = _nPerfMsg; // Message identifier
_copyData.cbData = sizeof(_msg); // size of data
_copyData.lpData = &_msg; // data structure
// Call function, passing data in &_msg
long nRetCode = -1;
if ( _hPerfWnd != NULL )
{
HWND hWnd = GetForegroundWindow();
if (hWnd == NULL)
hWnd = GetDesktopWindow();
nRetCode = ::SendMessage( _hPerfWnd,
WM_COPYDATA, //private message works here
(WPARAM)(HWND) hWnd, //windows sending the data
(LPARAM)(LPVOID) &_msg);
}
return nRetCode;
}
****************************
ON THE C# .NET SIDE
****************************
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == (int) Msgs.WM_COPYDATA)
{
COPYDATASTRUCT copyData = (COPYDATASTRUCT) Marshal.PtrToStructure(m.LParam, typeof(COPYDATASTRUCT));
if ((object) copyData != null)
{
IntPtr nPerfMsg = copyData.dwData;
if (nPerfMsg.ToInt32() == _nPerfMsg)
{
TSMSG msg = (TSMSG) Marshal.PtrToStructure(copyData.lpData, typeof(TSMSG));
int nRetCode = ProcessMessage(ref msg);
m.Result = (IntPtr) nRetCode;
return;
}
}
}
base.WndProc(ref m);
}
Structure definition on the MFC C++ side
----------------------------------------
#ifdef __cplusplus
extern "C" { // Assume C declarations for C++
#endif
typedef struct tagTSMSG
{
int nMsgID;
int nObjectID;
int nValue;
int nInstID;
}TSMSG;
#ifdef __cplusplus
} // End of extern "C" {
#endif // __cplusplus
Structure definitions on the .NET side:
--------------------------------------
[StructLayout(LayoutKind.Sequential)]
public struct TSMSG
{
public int nMsgID;
public int nObjectID;
public int nValue;
public int nInstID;
}
[StructLayout(LayoutKind.Sequential)]
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}
Gaulles
|
|
|
|
|
I have a treeview/listview combo I’m using as a mechanism to select folders and files to become the contents of a “backup job” file. Every entry in the treeview and listview has a checkbox next to it for selection.
This job file will be used by a windows service that will wake up, read the job file and copy folder/files to another mapped drive according to the contents of the job file….
I need to build some sort of string array or linked list that can grow/shrink dynamically, that mirrors the user’s selections… so every time the user checks a checkbox for a given selection, the path string is added to the string array/linked list, and removed when the box is unchecked… then when the user clicks “create jobfile”, the array/linked list is written out to a file.
Is a linked list the best way to go here, or is there a better choice using the .NET framework?
thanks.
|
|
|
|
|
I found this artical and it's been a great help. Only thing is I need to set dWord values greater than 2,147,483,647! I am sure that somebody has found a way around this.
Here is my code:
RegistryKey regKey = Registry.LocalMachine.CreateSubKey(@"SYSTEM\CurrentControlSet\Services\nsunicast\Parameters\Virtual Roots\/"+eId);
regKey.SetValue("MaxBandwidth", 4294967295); // if I change this to below the number above it will set as a dWord all day long.
Any examples, or ideas would rock.
Thanks,
Bill K.
|
|
|
|
|
DWORD = UInt32; //all day long (what ever you meant be that)
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
leppie wrote:
DWORD = UInt32;
I am not exactly sure how to use that?
I did try this and I got no compile errors. I did however still get a string in the reg and not a dword as desired?
UInt32 maxValue = 4294967295;
regKey.SetValue("MaxBandwidth", maxValue);
Thanks,
Bill K.
|
|
|
|
|
codeweenie wrote:
I did however still get a string in the reg and not a dword as desired?
I don't think you can create anything else using the .NET Registry handlers.
Either use Interop to get at the API registry functions or convert to and from a string using SetValue.
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
Paul Riley wrote:
Either use Interop to get at the API registry functions or convert to and from a string using SetValue.
Can you show me an example? I am not following you. Thing is the value that I am writing into the registry is a value that Windows Media Streaming server needs. This is not for a program of my own. I am trying to automate some stuff so converting it to or from a string is not really the answer, I don't think. I am able to feed the value in as a dword value as long as I keep it below that 2147483647 number and do it like this:
regKey.SetValue("MaxBandwidth", 2147483647);
However if I try to do this, the number gets converted to a string:
regKey.SetValue("MaxBandwidth", 4294967295);
So then I tried this:
UInt32 maxValue = 4294967295;
regKey.SetValue("MaxBandwidth", maxValue);
This also gets converted to a string.
Thanks,
Bill K.
|
|
|
|
|
codeweenie wrote:
This is not for a program of my own. I am trying to automate some stuff so converting it to or from a string is not really the answer, I don't think.
You are correct, so you need to use Interop.
This is slightly complicated at first but once you get the hang of it, it's quite easy (that's the story of everything .NET, in my experience). This[^] is a fair introduction to Interop. Other than that, you can search for DllImport/DllImportAttribute here and on MSDN and find more detailed examples.
Once you understand that, it's just a case of looking up the API registry calls: RegOpenKeyEx and RegSetValueEx.
If you run into any more problems, come back and ask.
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
Try this perhaps:
UInt32 maxValue = 4294967295;
regKey.SetValue("MaxBandwidth", maxValue.ToString("X")); //???
or maybe add a byte[], I cant really see what you can do from the docs.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
leppie wrote:
regKey.SetValue("MaxBandwidth", maxValue.ToString("X")); //???
I tried this, and I get "FFFFFFFF" as my value in the reg. It's a string value of course. Not sure how to employ the byte[] stuff.
From the docs and what I can't find on MSDN's site, I agree, this is getting to be a real problem. I can't understand why M$ would have one of their servers expect a value that can't be set via another program, that just does not make sense to me. There has to be a way to set this. I can't believe that somebody has not created a work around for it. I am just to new to C# to know how to do it just yet.
Thanks,
Bill K.
|
|
|
|
|
Someone help me out!
On my old VB Application, I use
set fvapp = createobject("fldview.application")
to create the ole automation server, work on it and use
set fvapp = nothing
to close the server. It works perfect.
when I convert to C#, since there is no way to free the fvapp, the server will be keep runing until my VB app close.
How I force C# to close the external OLE server? using "fv = null" doesn't work.
it close the server's interface, but the exe file is running still in the task list.
|
|
|
|
|
Try Marshal.ReleaseComObject()
|
|
|
|
|
A lot of exe COM servers expose a fvapp.Quit method.
If that's not enough, try sending the WM_QUIT message.
|
|
|
|