Finding what you need in the Microsoft® Visual Studio® 2005 documentation, which has over 200,000 topics, can be a daunting task. The Doc Detective is here to help, utilizing his investigative skills to probe the depths of the documentation.
Can’t find what you’re looking for? Just ask-if it’s in there, I’ll find it for you; if it isn’t, I’ll let you know that as well (and tell you where else you might go to find it).
Have a question for the Doc? Send your questions for future columns to me at docdetec@microsoft.com.
Dear Doc Detective,
I’ve been searching the Web for a long time, many places say it can be done, but I need some sample code. I’ve got a Link column in a DataGridView control, but would like it to be editable. How can I change the Link cell to a TextBox on the fly when the user presses a key, and back to a Link when the user is done?
On a separate note: everybody writes that you can use different cell types in one column. How?
- Weakest LinkCell in Weehawken
Dear Weakest,
The topic “Column Types in the Windows Forms DataGridView Control” provides a good overview of the Link column type, and the topic “How to: Customize Cells and Columns in the Windows Forms DataGridView Control by Extending Their Behavior and Appearance” covers customizing individual cells, but neither directly addresses your questions.
The Doc did some investigating and discovered that although it isn’t in the documentation, there are actually two ways to have different types of cells in the same column.
You can simply set a cell reference to a new cell type:
dataGridView1[3,3] = new
DataGridViewTextBoxCell();
Alternatively you can add a row with the cell types that you want:
DataGridView1.Rows.Add(New
DataGridViewTextBoxCell())
In your case, you can use the first method to change the Link cell to a TextBox then use it again to change back to a Link when they are done typing. And next time “everybody” writes that something can be done, believe them!
- Doc D
Dear Doc Detective,
I have a question about Setup and Deployment projects. I am including a .pdf and a .doc file in my Application Folder and wish to create shortcuts for both in the User’s Programs Menu. I cannot get Visual Studio 2005 to display the default icons for these files. Instead, I just get the generic icon. Can you help me fix this?
--Generic in Geneva
Dear Generic,
I think icon help. The docs could be a little clearer on this-the process for associating an icon with a file shortcut is exactly the same as associating an icon with your application. A shortcut will always use the generic icon unless you explicitly set its Icon property; Windows Explorer doesn’t know what file type your shortcut is pointing to.
This is described in the “To add an icon for your application” section of the topic “How to: Add and Remove Icons.” Assuming you have already added a shortcut to your file under User’s Program Menu in the File System Editor, you would do the following:
Select the shortcut, and in the Properties window select the Icon property.
Select Browse to open the Icon dialog box.
Click the Browse button. If you have already added the .ico file to your Setup project, select it, otherwise click Add File and browse to the location of your icon file on disk.
When you deploy your application, the icon that you selected will appear in the Programs menu for the shortcut.
As to where you would find the .pdf and .doc icons... I’m not sure. A quick search on my own machine didn’t find either one, so you may have to use an Icon extraction utility to pull them out of the .exe’s. A MSN Search on “extracting icons” brings up a number of options.
- Doctor D
Dear Doc Detective,
I’m having trouble printing a report based on a Grid control. I’ve written the logic for printing using a PrintDocument, but the one thing I can’t figure out is how to wrap the text. If the text in a given cell gets too large, it’s extending the LayoutRectangle, which isn’t what I want.
- Wrapped up in Yreka
Dear Wrapped,
If I understand you correctly, you are trying to print the contents of a data grid (DataGridView) control and the LayoutRectangle is changing in size based on the amount of text in a given cell. If you want the LayoutRectangle size to remain constant, you can do so changing the StringFormat settings. The article “Printing Reports in Windows Forms” describes this in detail.
- the Doc
Doc’s Doc Tip of the Day
As great as we all know the Visual Studio docs are, occasionally we all come up with questions for which we can’t find an answer. What to do? You can always wait for the next issue of CoDe Magazine and hope that the Doc has the answer, but if you need it fast you can always try posting a question in the MSDN Forums (forums.microsoft.com/MSDN).
There are individual forums for everything from Visual Basic or C# development to architecture to game technologies, and with 250,000 registered users it’s likely that someone will have a quick answer. Here are some tips for getting your questions answered promptly:
Post to the appropriate forum-if you don’t know which forum to go to, post an inquiry in the “Where Is The Forum For...?” forum.
Use a descriptive title for your post- “How do I format currency in a DataGridView text cell?” is much more likely to get an answer than “Help me!”
In your post, be succinct in describing your problem-a brief description of what you are trying to accomplish, what isn’t working, and what you have tried so far.
If you include code, keep it short and to the point-it’s not likely that anyone is going to read through 250 lines of code to try and understand your problem.
Be polite-remember that forum participation is voluntary and nobody has to help you, so thank them when they do and mark your question as answered so that others can quickly find the answer.
While you’re in there, try and answer a few questions yourself-you may be surprised by the things that you know and others don’t!
Found a topic in Help that doesn’t help? Tell the Visual Studio documentation team about it at vsdocs@microsoft.com.
URLs
http://msdn2.microsoft.com/en-us/library/bxt3k60s.aspx
http://msdn2.microsoft.com/en-us/library/7fb61s43.aspx
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/printwinforms.asp
http://forums.microsoft.com/msdn/default.aspx?siteid=1
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=881&SiteID=1