Customize how Visual Studio creates captions for data-bound controls
Note
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
When you drag items from the Data Sources Window onto the Windows Forms Designer, a special consideration comes into play: the column names in the caption labels are reformatted into a more readable string when two or more words are found to be concatenated together. You can customize the way in which these labels are created, by setting the SmartCaptionExpression, SmartCaptionReplacement, and SmartCaptionSuffix values in the HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Data Designers registry key.
Note
This registry key does not exist until you create it.
Smart captioning is controlled by the regular expression entered into the value of the SmartCaptionExpression value. Adding the Data Designers registry key overrides the default regular expression that controls caption labels. For more information about regular expressions, see Using Regular Expressions in Visual Studio.
The following table describes the registry values that control caption labels.
Registry item | Description |
---|---|
SmartCaptionExpression | The regular expression used to match your patterns. |
SmartCaptionReplacement | The format to display any groups matched in the SmartCaptionExpression. |
SmartCaptionSuffix | An optional string to append to the end of the caption. |
The following table lists the internal default settings for these registry values.
Registry item | Default value | Explanation |
---|---|---|
SmartCaptionExpression | (\\p{Ll})(\\p{Lu})|_+ | Matches a lowercase character followed by an uppercase character or an underscore. |
SmartCaptionReplacement | $1 $2 | The $1 represents any characters matched in the first parentheses of the expression, and the $2 represents any characters matched in the second parentheses. The replacement is the first match, a space, and then the second match. |
SmartCaptionSuffix | : | Represents a character appended to the returned string. For example, if the caption is Company Name , the suffix makes it Company Name: |
Caution
You should be very careful when doing anything in the Registry Editor. Back up the registry before editing it. If you use the Registry Editor incorrectly, you can cause serious problems that may require you to reinstall your operating system. Microsoft does not guarantee that problems that you cause by using the Registry Editor incorrectly can be resolved. Use the Registry Editor at your own risk.
To modify the smart captioning behavior of the Data Sources window
Open a command window by clicking Start and then Run.
Type
regedit
in the Run dialog box, and click OK.Expand the HKEY_CURRENT_USER node.
Expand the Software node.
Expand the Microsoft node.
Expand the VisualStudio node.
Right-click the 10.0 node, and create a new Key named
Data Designers
.Right-click the Data Designers node, and create a new String Value named
SmartCaptionExpression
.Right-click the Data Designers node, and create a new String Value named
SmartCaptionReplacement
.Right-click the Data Designers node, and create a new String Value named
SmartCaptionSuffix
.Right-click the SmartCaptionExpression item, and select Modify.
Enter the regular expression you want the Data Sources window to use.
Right-click the SmartCaptionReplacement item, and select Modify.
Enter the replacement string formatted the way you want to display the patterns matched in your regular expression.
Right-click the SmartCaptionSuffix item, and select Modify.
Enter any characters you want to appear at the end of the caption.
The next time you drag items from the Data Sources window, the caption labels are created using the new registry values provided.
To turn off the smart captioning feature
Open a command window by clicking Start and then Run.
Type
regedit
in the Run dialog box, and click OK.Expand the HKEY_CURRENT_USER node.
Expand the Software node.
Expand the Microsoft node.
Expand the VisualStudio node.
Right-click the 10.0 node, and create a new Key named
Data Designers
.Right-click the Data Designers node, and create a new String Value named
SmartCaptionExpression
.Right-click the Data Designers node, and create a new String Value named
SmartCaptionReplacement
.Right-click the Data Designers node, and create a new String Value named
SmartCaptionSuffix
.Right-click the SmartCaptionExpression item, and select Modify.
Enter
(.*)
for the value. This will match the entire string.Right-click the SmartCaptionReplacement item, and select Modify.
Enter
$1
for the value. This replaces the string with the matched value, which is the entire string so that it will remain unchanged.The next time you drag items from the Data Sources window, the caption labels are created with unmodified captions.