VIBlend
Home Products Downloads Purchase Support Forum About Blog

WinForms DataGridView Search Functionality

by viblend 7. May 2012 00:50

In the latest version of VIBlend Controls for WinForms, we added a new utility control called vDataGridViewSeachHeader.
This small control adds a Search Functionality to the DataGridView and allows the users to easily find a record in a large data set. The post will show you how to associate this control to an instance of the vDataGridView control.

- Drag and drop a new instance of the vDataGridViewSearchHeader.
- Drag and drop a new instance of the vDataGridView.
- Set the DataGridView property of the vDataGridViewSearchHeader to point to your vDataGridView instance.

Here are the DataGridView and its Search Header at design-time.



In the code behind, bind the Grid to a DataTable. In the post, we will use a sample data.

C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VIBlend.WinForms.DataGridView;

namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            DataTable table = new DataTable();
            for (int i = 0; i < 100; i++)
            {
                table.Columns.Add("Column " + i);
            }

            for (int i = 0; i < 100; i++)
            {
                string[] values = new string[100];
                for (int j = 0; j < 100; j++)
                {
                    values[j] = "Cell " + i + "." + j;
                }
                table.Rows.Add(values);
            }
            this.vDataGridView1.DataSource = table;
            this.vDataGridView1.ColumnsHierarchy.AutoResize();

        }
    }
}

 
VB .NET

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports VIBlend.WinForms.DataGridView

Namespace WindowsFormsApplication6
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()

            Dim table As New DataTable()
            For i As Integer = 0 To 99
                table.Columns.Add("Column " & i)
            Next i

            For i As Integer = 0 To 99
                Dim values(99) As String
                For j As Integer = 0 To 99
                    values(j) = "Cell " & i + AscW("." )+ j
                Next j
                table.Rows.Add(values)
            Next i
            Me.vDataGridView1.DataSource = table
            Me.vDataGridView1.ColumnsHierarchy.AutoResize()

        End Sub
    End Class
End Namespace

Here's the result:


Comments are closed

About the author

Some text that describes me

Tag cloud

Recent comments

Comment RSS
Copyright © 2011 VIBlend  
ALL RIGHTS RESERVED  
 
Terms of Use | Privacy Policy
WinForms Controls Purchase Online About Us
       
DataGrid Navigation Pane Technical Support Blog
ScrollBar TreeView
ListBox ProgressBar Downloads Register
ComboBox Buttons
TabControl Editors Documentation Client Login

VIBlend Blog is powered by BlogEngine.NET