DataGridView CodeSample - Faking Password character and loading image in CellFormatting
Categories: Lists & Grids, Non-ORM
|
Tags: Architects, Developers, Resource Handlers, C#, VB.NET, 1. Beginner, 2. Intermediate, 3. Advanced, v6.3, v6.4 and Later
Revision:
1
Posted:
17/Dec/2009
Updated:
23/July/2010
Status:
Publish
Types: Code
|
This article will have a few sections added to it soon, based on the following article type skeleton: CodeSample OverviewThis article will demonstrate how you can use CellFormatting event in DataGridView "fake" passwordcharacter, by outputting dummy asterisks in the password columns.
Samples of useVB.NET Code
''' <summary>
''' CellFormatting gets fired for every column of every row, including the
''' empty row at the bottom, as we allow adding new rows in this sample DataGridView.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub DataGridView1_CellFormatting(ByVal sender As System.Object, ByVal e As Gizmox.WebGUI.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
If e.RowIndex > DataGridView1.Rows.Count() _
OrElse e.RowIndex < 0 _
OrElse DataGridView1.Rows(e.RowIndex) Is Nothing _
OrElse DataGridView1.Rows(e.RowIndex).DataBoundItem Is Nothing Then
' Special handling for the bottom empty row.
e.Value = Nothing
ElseIf e.ColumnIndex = 2 AndAlso e.Value IsNot Nothing Then
' For our image column, create the resource handle out of the image name.
e.Value = New ImageResourceHandle(e.Value)
ElseIf e.ColumnIndex = 1 Then
' Faking password character
e.Value = "*********"
End If
End Sub
C# Code
// '' <summary>
// '' CellFormatting gets fired for every column of every row, including the
// '' empty row at the bottom, as we allow adding new rows in this sample DataGridView.
// '' </summary>
// '' <param name="sender"></param>
// '' <param name="e"></param>
// '' <remarks></remarks>
private void DataGridView1_CellFormatting(object sender, Gizmox.WebGUI.Forms.DataGridViewCellFormattingEventArgs e)
{
if (((e.RowIndex > DataGridView1.Rows.Count )
|| ((e.RowIndex < 0)
|| ((DataGridView1.Rows[e.RowIndex] == null)
|| (DataGridView1.Rows[e.RowIndex].DataBoundItem == null)))))
{
// Special handling for the bottom empty row.
e.Value = null;
}
else if ((e.ColumnIndex == 2) && (e.Value != null))
{
// For our image column, create the resource handle out of the image name.
e.Value = new ImageResourceHandle((string) ( e.Value ));
}
else if ((e.ColumnIndex == 1))
{
// Faking password character
e.Value = "*********";
}
}
The demo applicationThe demo application is a very simple DataGridView to a DataTable with 4 rows of data. One of the columns contains a name of an image, an on CellFormatting we create a ResourceHandle the DataGridViewImageColumn, out of that image name. The image itself is stored on the Resources.
Tips and TricksIn CellFormatting you need to take special care if you allow adding of new rows to the grid. See the demo for one way to do that. SDK Version highlights- This sample requires version 6.4 or higher for some of the DataGridView to fully work.
RererencesCode samples
About the author
Related Articles
|
Lists & Grids
|
|
|
I played a bit around with the new 6.4 ListView control, its quite amazing what you can do with it. It opens a lot of new ways to present data in a better and more userfriendly way.
Tags:
Architects, Developers, Data Binding, C#, 2. Intermediate, 3. Advanced, Customization, Data Binding, v6.4 and Later
|
|
|
Tags:
Developers, Data Binding, 2. Intermediate, 3. Advanced, Customization, Layouting, Pre v6.3, v6.3, v6.4 and Later
|
|
|
Tags:
Developers, Data Binding, Navigation, 1. Beginner, 2. Intermediate, Data Binding, Navigation, ASP.NET, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
|
|
|
Tags:
Architects, Developers, Data Binding, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
|
|
|
Tags:
Developers, Data Binding, Windows & Dialogs, 1. Beginner, 2. Intermediate, Customization, Data Binding, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
|
|
|
The DataListView control is an extension to the Visual WebGui ListView. It inherits from the Visual WebGui ListView control and adds DataSource/DataMemeber support to provide a DataGridView behavior in terms of data population.
Tags:
Developers, Data Binding, 1. Beginner, 2. Intermediate, 3. Advanced, Data Binding, Pre v6.3
|
|
|
|