473,396 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I filter datagridview exported from excel in VB.NET

2
I have a datagridview which i import an excel file.my excel columns are name,id,sex,grade,seat no .what i want is to filter all the datagridview via a textbox. i.e. when i type a single word in the text box i want it to filter the rows of the DGV at the same time.

Here is the code i use to import the excel to the datagridview....

Expand|Select|Wrap|Line Numbers
  1. Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
  2.         Dim filePath As String = OpenFileDialog1.FileName
  3.         Dim extension As String =
  4.         Path.GetExtension(filePath)
  5.         Dim header As String = If(rbHeaderYes.Checked, "YES", "NO")
  6.         Dim conStr As String, sheetName As String
  7.         conStr = String.Empty
  8.         Select Case extension
  9.             Case ".xls"
  10.                 'Excel 97-03
  11.                 conStr = String.Format(Excel03ConString, filePath, header)
  12.                 Exit Select
  13.             Case ".xlsx"
  14.                 'Excel 07
  15.                 conStr = String.Format(Excel07ConString, filePath, header)
  16.                 Exit Select
  17.         End Select
  18.         'Get the name of the First Sheet.
  19.         Using con As New OleDbConnection(conStr)
  20.             Using cmd As New OleDbCommand()
  21.                 cmd.Connection = con
  22.                 con.Open()
  23.                 Dim dtExcelSchema As DataTable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
  24.                 sheetName = dtExcelSchema.Rows(0)("TABLE_NAME").ToString()
  25.                 con.Close()
  26.             End Using
  27.         End Using
  28.         'Read Data from the First Sheet.
  29.         Using con As New OleDbConnection(conStr)
  30.             Using cmd As New OleDbCommand()
  31.                 Using oda As New OleDbDataAdapter()
  32.                     Dim dt As New DataTable()
  33.                     cmd.CommandText = (Convert.ToString("SELECT * From [") & sheetName) + "]"
  34.                     cmd.Connection = con
  35.                     con.Open()
  36.                     oda.SelectCommand = cmd
  37.                     oda.Fill(dt)
  38.                     con.Close()
  39.                     'Populate DataGridView.
  40.                     DataGridView1.DataSource = dt
  41.                 End Using
  42.             End Using
  43.         End Using
  44.     End Sub
Aug 13 '16 #1
2 1837
madankarmukta
308 256MB
As per my understanding, you can filter the data of the DGV by identifying the Indicator that identifies the row . Which column from the imported data identifies the row. You need to add extra column in the grid for that.

I have suggestions on how you can code this but prior to that could you please put your code here which you tried to filter the data.
Aug 13 '16 #2
adkmar
2
I haven't done any coding yet. i need you to suggest the code for me.
Aug 15 '16 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Morten Snedker | last post by:
Hi folks, I'm trying to get the actual content of a datagridview into Excel. It seems to me that the most easy way is to use the WriteXML property of a dataset. So that's what I'm trying, but...
1
by: martin1 | last post by:
Hi, All, DataGridView is populated with all coumns from database since i need some columns data for condition statement, after that I want to show rest of column in the DataGridView, so how to...
5
by: Mike Wilson | last post by:
Hello all, I'd like to export a DataGridView to Excel. I am using .NET 2.0 and VB.NET. But I don't know if the user has Excel on their machines, so can't use COM Excel object. Any ideas...
1
by: pompair | last post by:
Hi, I've been implementing a program that populates winforms DataGridView from an excel sheet (.xlsx-file). The app works ok. Now I'm refactoring it and I've got a feeling that databinding...
1
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons:...
0
by: Big P | last post by:
Hello, I would like to filter multiple rows in DataGridView ( VB Express) My form has 3 Textboxes, 1 Button and 2 DataGridViews. The datagridview1 has 3 columns of data. My datagridview1 looks...
0
by: mootoon | last post by:
make datagridview export to excel, but Headcolumn don't show in excel files. Sample result (in Excel) 1 | mani | 213/435 | 0-892-342234-09 2 | ware | 1/67 | 053-36-49 But i need resuult...
5
by: leelaprasad9999 | last post by:
hi i'm trying to export datagridview data with image to excel , i'm using the below code, but image cannot be displayed. Microsoft.Office.Interop.Excel.Application ExcelApp = new...
0
by: adkamr | last post by:
I have a datagridview which i import an excel file.my excel columns are name,id,sex,grade,seat no .what i want is filter all the columns (multi column filter) in the datagridview except name and id...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.