Serial Number In Datagridview Vb Net String

/ Comments off
Active4 years, 7 months ago
String

I wish to format a string for display as a serial number e.g.

Nov 26, 2013  Hi, How can add a row number to a useless row (Row header) of a datagridview. See below screenshot. Thanks for inputs. Srini A quick and simple solution is to set the row's HeaderCell value. You can do this when a new row is added and when a row is removed, iterate over all rows and update their header values. Private Sub DataGridView1RowsAdded.

to Romancing saga 3 hack rom download free.

if it was numbers i could

but if it is a String this doesn't work. Can anyone help me in a direction?

  1. The information is displayed in 16 char for easy reading and understanding some values are 2AFHY89 and must be recorded as such

  2. It is displayed several different ways/times e.g. label, Textbox, DataGridView,

  3. I don't understand IFormatProvider, ICustomFormatter so if the value did not have [a-z] i could just use the above example('0000-0000-0000-0000')

  4. I wish to use a format NOT alter the data stored both examples are not a format just editing the stored data.

John
JohnJohn
3853 gold badges6 silver badges25 bronze badges

2 Answers

You can pad the serial number with zeros to get the full 16 characters, then split it into 4 character parts and then join the parts with '-' between them.

Blackwood

Serial Number In Datagridview Vb Net String Length

Blackwood
4,16412 gold badges24 silver badges39 bronze badges

If you want '00' on the front, just add it, even if temporarily in a function. If it is meant to be some sort of padding, add that to the procedure when the length requires it (question is not clear if it is indeed, left padding).

Usage:

Output:

00ab-c123-45d6-7890

This acts like an IFormatProvider but in the form of a Shared function. In other cases, an actual IFormatProvider might be better.

Notes

  1. It is a bit odd for any sort of formatter to add characters as in the padding function. Generally, formatting just controls how a string is displayed. If the serial is supposed to display as 16 characters, it probably ought to have 16 characters.
  2. You can easily add new formats such as an 'R' format for Raw where the dashes are omitted.
Ňɏssa PøngjǣrdenlarpŇɏssa Pøngjǣrdenlarp
35.9k11 gold badges41 silver badges116 bronze badges

Not the answer you're looking for? Browse other questions tagged vb.netformatstring-formatting or ask your own question.