Reputation: 5545
Initial Position: I have bound a typed Dataset (populated with data from sql query) to a DGV. The DGV entries are not for editing just for reading. The DGV has 12 rows (Months).
Problem: Now I am trying to display the months names instead of the numbers you could say I want to label the values (1 = January, 2 = February etc.) but dont know how to do it.
What I tried: My idea was to create and use an unbound table (values; months names) but I cannot find an column-type (DGV -> Edit Columns) that could perform what I want.
EDIT: Hello, no, it is not about the header. I give you an example.
ATM it looks like:
1|true|
2|false|
3|false|
... My goal is:
January|true|
Feburary|false|
March|false|
Upvotes: 1
Views: 46
Reputation: 205
Maybe you could try the event "CellFormating". In web it would be simple since there is an event raised after each row data bound, but not in windows form unfortunately.
I suggest that you change the value of the month directly in the CellFormating event as follow :
Private Sub DataGridView1_CellFormatting(sender As Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
If e.Value IsNot Nothing AndAlso IsNumeric(e.Value) Then
e.Value = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(e.Value)
End If
End Sub
I just tested this code and works perfectly.
Upvotes: 1