Binding items and ICON image to ListView creates unwanted space, between the Text and ICON. Is there a way to remove the space. This is .net Win Form app. No spaces in the text.
Thanks
CodePudding user response:
There are a few ways to remove extra spaces from a C# ListView control:
Use the Trim() method on the strings in the ListView control.
Use the String.Replace() method to replace all whitespace characters with an empty string.
Use a regular expression to replace all whitespace characters with an empty string.
CodePudding user response:
Your image shows whitespace at the beginning of each string, so the simplest way to do this is via yourString.TrimStart(' ');
which will remove all leading occurrences of the char you want to remove
Also worth noting that TrimStart takes multiple arguments of chars that it can trim from the beginning, so if you know ahead of time that other leading characters may be a problem, you can pass them in as arguments to process out all