Usually it is better to leave things at their default. So your connection string is stored in the app.config file (or web.config one for web apps). In this way it is easy to adjust the configuration when you deploy your app to your customer.
If that path is stored in the web.config or app.config and your app reads it at runtime then you could edit (manually or using a setup tool) the path at your customer location to match its constraints and the program will use the new configuration . The DataDirectory substitution string is a compromise to alleviate the setup reconfiguration problems; if you plan to change it via code then you face the same problem, because you still have to read the customer config somewhere.
Anyway, changing the location resolved by |DataDirectory| is easy enough from code.
AppDomain.CurrentDomain.SetData("DataDirectory", your_path_to_a_data_folder);
By the way, the advice from marc_s is a very good one. If you have Sql Server Express installed (and you need it also on the customer machine) then you add your MDF file to the database handled by Sql Server Express using its administrative tool (Sql Server Management Studio). This gives you a logical name for your db (not a file name with its changing path) and in your connection string you use that logical name INSTEAD OF the AttachDbFileName
key
DataSource=.\SQLEXPRESS;Database=myDatabaseName; ....;
As an alternative, if you don't need to have a shared access to your database from many PC on the customer LAN then you could look at the LocalDB option for Sql Server Express. This option allows you to not install Sql Server Express to your customer PC but start the database services as a local dll for your own app.
See LocalDB deployment on local PC