473,406 Members | 2,954 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,406 software developers and data experts.

VB.NET DataGridView ColumnHeader Click

I am reading an excel file into a datagridview and trying to perform some function based on the column header that is clicked. I currently can produce an event to occur (msgbox) but, I need to get the current columnheader clicked, not the current column header that is selected. IF anyone has any knowledge of this please help.

This is the loading of excel file:

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  2.         Dim ClientsFile = TextBox1.Text
  3.         'MsgBox(ClientsFile)
  4.         Dim con As OleDbConnection
  5.         Dim da As OleDbDataAdapter
  6.         Dim ds As New DataSet
  7.  
  8.         If ClientsFile <> "" Then
  9.             Try
  10.                 con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & ClientsFile & ";Extended Properties=Excel 8.0")
  11.                 con.Open()
  12.                 da = New OleDbDataAdapter("select * from [Sheet1$]", con)
  13.                 da.TableMappings.Add("Table", "SAMPLE")
  14.                 da.Fill(ds)
  15.                 DataGridClient.SortOrder.Ascending()
  16.  
  17.                 DataGridClient.DataSource = ds.Tables(0).DefaultView
  18.             Catch ex As Exception
  19.                 MsgBox(ex.Message)
  20.             Finally
  21.                 con.Close()
  22.             End Try
  23.         End If
  24.     End Sub
  25.  
Here is the current code I am using to perform the event capture:

Expand|Select|Wrap|Line Numbers
  1.  Private Sub DataGridClient_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridClient.ColumnHeaderMouseClick
  2.         Dim clickedColumn As String
  3.         Dim iRow As Integer = DataGridClient.CurrentRow.Index
  4.         Dim iCol As Integer = DataGridClient.CurrentCell.ColumnIndex
  5.         Dim RowName As String = DataGridClient.Columns(iCol).HeaderText
  6.  
  7.         If e.Button = Windows.Forms.MouseButtons.Right Then
  8.             Dim hit As DataGridView.HitTestInfo = DataGridClient.HitTest(e.X, e.Y)
  9.             If hit.Type = DataGridViewHitTestType.ColumnHeader Then
  10.                 'this does not produce anything
  11.                 clickedColumn = DataGridClient.Columns(hit.ColumnX).HeaderText
  12.             End If
  13.         End If
  14.  
  15.         MsgBox(clickedColumn)
  16.  
  17.         ListBox1.Items.Add(RowName)
  18.     End Sub
  19.  
Oct 11 '07 #1
1 10500
Zechs
1
Dim iCol As Integer = e.ColumnIndex
This will get the index of the header that u click.
While e As System.Windows.Forms.DataGridViewCellMouseEventArg s
Dec 28 '10 #2

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

Similar topics

1
by: joannelai | last post by:
Hi all, In my project I have a ListView and a ColumnClick event is added to sort the clicked column. I want to have a Context Menu when the ColumnHeader is right clicked, but I find no way to...
10
by: rob | last post by:
I have a class that among others exposes a string property "Date". The date in this property is stored in the form yyyymmdd. Now I do the following 1) Generate a DataGridViewTextBoxColumn column...
1
by: Dave A | last post by:
Hi, I am struggling with two way databinding in WinForms and the DataGridView. I am binding to business object classes (rather than datatables). If I have a collection of these business...
6
by: Satya | last post by:
Hi, I am using a DataGridView to display a large amount of data and so need to use filters for displaying certain data. For this I want to provide a textbox for each column of the DataGridView so...
1
by: Saravanan | last post by:
Hi, I am using DataGridView for displaying data I want to some idea about the following 1. How to split and merge cells in DataGridView 2. How to place column header in the bottom of the cell...
0
by: windy | last post by:
Hi all, how can i add tooltip for columnheader on datagridview? Thanks.
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
0
by: =?Utf-8?B?UmljaA==?= | last post by:
In a datagridview, the first column header cell is columnHeader(0), which is immediately to the right of the Top Left Corner Select All cell. And the first RowHeader cell is RowHeaderCell(0) which...
2
by: Steve | last post by:
Hi All I am using VB.net 2005 windows forms I use the Datagridview.cellformatting event to change the colours of individual cells as required and all works fine How can I do the same for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.