|
The column and table styles should be assigned before you set the DataGrid.DataSource .
If you actually read the documentation for DataGrid.DataSource , you'll see that any IList or IListSource will do. You can assign either a DataSet or DataTable , but I recommend assigning the DataSet to DataGrid.DataSource and the name of the table to DataGrid.DataMember . Finally, make sure that for your DataGridTableStyle you set the MappingName to the DataTable name (if you follow my advice above, this would be the same as the DataGrid.DataMember name, but still works if you assign the DataTable to the DataGrid.DataSource instead). The documentation for the DataGridTableStyle.MappingName describes this, as well as what to assign as the MappingName if you're reflecting against IList or IListSource implementations besides the DataSet and DataTable classes.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi all,
I have a combo box and a text box on a form. cmb1 and txt1 for arguments sake. The tab order means that when tab is pressed focus moves from cmb1 to txt1. What i want to do is allow for the user to press the enter key and simulate the tab key being pressed, i.e. focus moves to the next control on the tab order.
Any ideas?
Cheers
Kev
|
|
|
|
|
You could check for the Enter key in the combo's KeyPress event, then transfer focus to the next in the tab order.
private void comboBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ( e.KeyChar == (char)13 )
{
this.GetNextControl(this.ActiveControl, true).Focus();
}
}
Roger Stewart
"I Owe, I Owe, it's off to work I go..."
|
|
|
|
|
You should actually use KeyCode.Enter . While this will probably always be character code 13, without optimization (based on the compiler) (char)13 may require additional instructions for the cast while using KeyCode.Enter will always compile to 13 without a cast.
Besides, it's best to avoid "magic numbers" and makes for more elegant code.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I took this (the char 13) straight out of MSDN Library for the KeyPressEventArgs.KeyChar Property[^]. You might want to pass your suggestion on to MSDN Lib guys
Roger Stewart
"I Owe, I Owe, it's off to work I go..."
|
|
|
|
|
Thanks Roger,
Works great.
Kev
|
|
|
|
|
I'm trying to create rotatable widgets. I tried to rotate the graphic surface but that is not enough, I have to rotate the clip rectangle of the components too, in order to create the right paint area and to receive the mouse events in the correct way. Alternatively, I created my own components from scratch, and implemented everything, but I would rather use .Net components and just extend them. But I'm not sure if that is possible. Is there anybody who knows if it is possible and, if yes, how can I?
I am using C# with .Net 1.1.4322.
|
|
|
|
|
The Graphics class defines several helpful transformation methods like Graphics.RotateTransform for this specific purpose. If you apply this as the world transform, than even your clipping region (whether you fill a Region yourself or use a GraphicsPath (most handy, BTW!) is rotated.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thank you. But, I'm sorry, I don`t understand what you mean for "apply this as the world transform". If I extend a Button Class and I call RotateTransform to its Graphic obj it will only change the graphic surface, but not the . Can you give me a little example of your solution?
|
|
|
|
|
Because a Button isn't completely drawn by .NET. You must understand that almost every control in Windows Forms encapsulates the native Windows Common Controls which draws the control unless you completely handle the painting yourself by calling the following in your constructor:
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint,
true); For examples of transforms read the class documentation in the .NET Framework SDK that was installed by default when you installed VS.NET (or the standalone SDK) or available online at http://msdn.microsoft.com/library[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
First I'd like to point out that I am posting this anonymously to protect the identities of myself and those I work with.
At a design review meeting recently, a collegue of mine stated that we shouldn't use the reflection assembly in out software as using reflection was 'cheating'.
I have to say that I was completely speechless. My collegue appears to think that reflection is cheating as it allows you to bypass the class structure.
Personally I think that reflection is a useful addition to the .NET libraries and allows us to write flexible code.
Any views?
|
|
|
|
|
Fear of the unknown is a big reason for people to not like new ideas. Show some examples of how benefical reflection can be. However anything can be abused so make sure your proposed design isn't abusing reflection and that another sound design wouldn't work. Reflection used correctly can add great power, maintainability and flexability to a design.
Examples:
1) A pluggable container system that allows any component to be loaded/unloaded at runtime without the need to stop the server
2) Ability to use different adapters that can be configured through a external text file. I used this quite a bit and it saved an enormous amount of time and coding effort.
What exactly did you propose using reflection for?
-
Drew
|
|
|
|
|
Reflection is not cheating, it is just another tool in the toolbox. Like most other techniques (inheritance, singletone, etc) it can be used inappropriately, but that is no reason to dismiss it out of hand.
my blog
|
|
|
|
|
hello,
i'm looking for an open source implementation of a user modeling for information retrieval project.
the project is written in c# and the part i'm looking for should create a user profile for a specific web pages google retrieves.
if anyone heard of such an open source code, i'll be more than happy to hear about it.
my email is: kruhd@bgu.ac.il
thankyou,
Doron.
|
|
|
|
|
Hi there!
I want to know if you can help me in two little things.
First of all, I´m trying to put a XML new element in an existing XML.
The new element would be like this <name>C:\deco.mpg</name>
I´m trying to make this with this instructions
XmlElement elem = doc.CreateElement("name");
elem.InnerText = C:\deco.mpg;
node.AppendChild(elem);
but in XML appear like this
<name xmlns="">C:\deco.mpg</name>
How can I eliminate the (xmlns="")?!!!
The other doubt is the following, if I want to create an element and elements inside, for example...
<video>
<filetype>mpg</filetape>
<name>deco</name>
</video>
How can I do this?!!
Thank you very much, Sèrgio
|
|
|
|
|
the answer to your second question is simple create a root element instead a child element by adding properties to the new created element
at hte first question i am not sure bu i thing that is the namespace, there must be an option about it, refer to msdn...
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
The xmlns you should not worry about. It will not affect your XML-related code. If you're worried about it for asthetic reasons, then you should either define a namespace (in most cases, your XML documents should have unique namespaces anyway) or write the raw element using an XmlTextWriter instead, calling the WriteRaw method. Other methods in the XmlTextWriter would also help as well, but you need to read the class documentation in the .NET Framework SDK to gain a better understanding.
For second problem, as the other user mentioned below, just create yet another element like you are now, or use elem.InnerXml propety like so:
elem.InnerXml = "<filetype>mgp</filetype><name>deco</name>";
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi!
How to convert the following VC++ code to C# code,what does the corresponding C# code look like?
HKEY CreateRegistryKey(DWORD *pdwStatus)
{
LONG lResult;
DWORD dwDisposition;
HKEY hKey = NULL;
lResult = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
subkey,
0,
NULL,
REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE,
NULL,
&hKey,
&dwDisposition
);
if(lResult == ERROR_SUCCESS)
{
if(dwDisposition == REG_CREATED_NEW_KEY)
{
*pdwStatus = REG_KEY_CREATED;
}
else if(dwDisposition == REG_OPENED_EXISTING_KEY)
{
*pdwStatus = REG_KEY_OPENED;
}
return hKey;
}
}
|
|
|
|
|
Why bother? Just use the Microsoft.Win32.RegistryKey class. Don't P/Invoke code (like RegCreateKeyEx ) if don't have to. This intrudoces additional security restrictions on your code. Microsoft has already define such methods in the BCL - and our assemblies are fully trusted - using the RegistryKey class I mentioned above.
If you want to learn more about P/Invoke, I suggest you start by reading Consuming Unmanaged DLL Functions[^] in the .NET Framework SDK.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi!Heath,
Thank you for your answer^^.
Best regards!
momer
|
|
|
|
|
Hello,
Can any body help me to add wrap text feature for ListView Control in C#.
In listview, we can not increase the width of the column but not height of the row.
I tried keeping a hidden image control and succeded in increasing the height of the row... but text is not wrapping verically.
The features should be just like..MS Excel Cell.
Thanks
Sundar
|
|
|
|
|
The ListView is not a good replacement for Excel-like spreadsheets. If you want something like that, I suggest a third-party control (not that expensive, really) like FarPoint's[^] Spread&tm;.
In order to draw a ListView how you want it, you have to "reach back" to the native APIs and use owner drawing like with the native Common Controls (because most of the Windows Forms controls - like the ListView - encapsulate the Windows Common Controls). Allen Anderson has such a control - and an article to explain it - at http://www.codeproject.com/cs/miscctrl/aa_listview.asp[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
Thank you for your reply.
I already tried Glacial ListView Control. I dont want complete replacement for Excel Spreadsheet. I have to write a custome control be extending the listview control by adding few features.
I did everything except the Word-Wrapping (Like Glacial ListView Control). If I can add this functionality my job is done.
Have any idea how to add this to existing listview?
Thanks
Sundar
|
|
|
|
|
Glacial ListView is using the existing List-View common control. Like I wrote previously, most of the controls - including the ListView control - are simply encapsulating the native common controls.
If you'd rather do this yourself, either look at the source for the Glacial ListView (that's why it's posted) or read the reference documentation for the List-View common control at http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/listview/reflist.asp[^]. If you're not familiar with P/Invoke (calling native functions in .NET), read Consuming Unmanaged DLL Functions[^] in the .NET Framework SDK, as well as Marshaling Data with Platform Invoke[^].
Again, if you want examples look at the Glacial ListView. While he isn't started with the ListView defined in the BCL, it really doesn't matter. He's still constrained by the Control class and almost everything implemented in that control you can implement because it's all going back to native code. The owner drawing is what you're interested in (specifically the NM_CUSTOMDRAW (-12) message, which you can read about at http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/listview/notifications/nm_customdraw_listview.asp[^]). All of these messages are sent through the WndProc defined by the Control class and overridden by every control in the .NET BCL to provide hooks (like to fire events or draw ornaments on controls).
Everything you need to know you can find in the article for the Glacial ListView as well as other articles on this site about owner drawing .NET Windows Forms Controls (which really is about owner drawing the common controls - just using managed code). I see no reason to duplicate those rather long articles here in the forums.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
Thank you veru much. You have given enough information. Now I can write what I require.
Thanks
Sundar
|
|
|
|