Change column value of Datagridview in Winform

Hi Experts,

I have data grid view, which displays data from a table. One column displays "S" or "I". I want to display "Student if it is "S" and "Instructor" if it is "I". I am using VB.net and windows form .

Please help.

Thanks.
RadhaKrishnaKiJayaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it_saigeDeveloperCommented:
You could use the CellFormatting Event of the DataGridView.  Example:
Public Class Form1
	Private People As New List(Of Person)()

	Private Sub OnLoad(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
		For i As Integer = 1 To 20
			People.Add(New Person() With {.ID = i, .Name = String.Format("Person{0}", i), .Role = If(i Mod 5 <> 0, "S", "I")})
		Next

		DataGridView1.DataSource = People
	End Sub

	Private Sub OnCellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
		If TypeOf sender Is DataGridView Then
			Dim grid As DataGridView = DirectCast(sender, DataGridView)
			If e.RowIndex <> -1 AndAlso Not String.IsNullOrEmpty(e.Value) Then
				If grid.Columns(e.ColumnIndex).DataPropertyName().Equals("Role") Then
					e.Value = If(e.Value.ToString().Equals("S"), "Student", "Instructor")
					e.FormattingApplied = True
				End If
			End If
		End If
	End Sub
End Class

Class Person
	Public Property ID() As Integer
	Public Property Name() As String
	Public Property Role() As Char
End Class

Open in new window

Produces the following output -Capture.JPG
-saige-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RadhaKrishnaKiJayaAuthor Commented:
It worked!! Thank you very much for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.