473,698 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridColumnN ame based on DataGrid.Curren tCell

Is it possible (and how?) to get the data grid column name
based on the DataGrid.Curren tCell?

The DataGrid has assigned a TableStyle comprising
selected columns (DataGridTextBo xColumn) from
the source DataTable (DataGrid.DataS ource=DataTable ).
I would like to be able to get the column name of the
datagrid based on the DataGrid current cell so I can reference
the appropriate column in the source DataTable.

Thanks,

--
Strah @ Langan
Nov 20 '05 #1
6 2911
You can use the ColumnIndex of the CurrentCell property to reference the
underlying datatable's colum.columnNam e property. So if ColumnIndex of the
current cell is 1, then you can use DataTable.Colum ns(1).ColumnNam e to get
this info. You can just substitute it where I hard coded 1.

HTh,

Bill
"Strahimir Antoljak" <st***@netzero. net> wrote in message
news:Oi******** *****@TK2MSFTNG P10.phx.gbl...
Is it possible (and how?) to get the data grid column name
based on the DataGrid.Curren tCell?

The DataGrid has assigned a TableStyle comprising
selected columns (DataGridTextBo xColumn) from
the source DataTable (DataGrid.DataS ource=DataTable ).
I would like to be able to get the column name of the
datagrid based on the DataGrid current cell so I can reference
the appropriate column in the source DataTable.

Thanks,

--
Strah @ Langan

Nov 20 '05 #2
use the mouse down event on the datagrid

and use System.Windows. Forms.DataGrid. HitTestInfo to get pos of column

something like:

objHitTest = Dgd.HitTest(e.X , e.Y)
Select Case objHitTest.Type
Case System.Windows. Forms.DataGrid. HitTestType.Cel l
strPartHit = "Cell"
Case System.Windows. Forms.DataGrid. HitTestType.Col umnHeader
strPartHit = "ColumnHead er"
Case System.Windows. Forms.DataGrid. HitTestType.Col umnResize
strPartHit = "Resize"
Case System.Windows. Forms.DataGrid. HitTestType.Cap tion
strPartHit = "Caption"
Case System.Windows. Forms.DataGrid. HitTestType.Par entRows
strPartHit = "ParentRows "
Case System.Windows. Forms.DataGrid. HitTestType.Row Header
strPartHit = "RowHeader"
If e.Clicks = 2 Then
'run your code here
End If
Case System.Windows. Forms.DataGrid. HitTestType.Row Resize
strPartHit = "RowResize"
Case System.Windows. Forms.DataGrid. HitTestType.Non e
strPartHit = "None"
Case Else
strPartHit = "Unknown"
End Select

from here get your currentrowindex
Nov 20 '05 #3
Hi Strah,

Can you try this one (it is one long sentence)
Dim name As String =
DataGrid1.Table Styles(0).GridC olumnStyles(Dat aGrid1.CurrentC ell.ColumnNumbe r
).MappingName

I hope this works easy?

Cor
Nov 20 '05 #4
thanks Hth but this would not work in my
case as I am using a TableStyle comprising
selected columns from the DataTable, which
means ColumnIndex property of the CurrentCell
does not necessarily match the column index
in the DataTable; the DataTable has 11 columns
while TableStyle can have any number of columns
between 2 and 11 - so I create TableStyle that
contains 2nd, 4th and 8th column in the DataTable,
but in DataGrid they have indices 0, 1, 2.

Thanks again,

--
Strah @ Langan

"William Ryan eMVP" <bi**@NoSp4m.de vbuzz.com> wrote in message
news:O4******** *****@TK2MSFTNG P11.phx.gbl...
You can use the ColumnIndex of the CurrentCell property to reference the
underlying datatable's colum.columnNam e property. So if ColumnIndex of the current cell is 1, then you can use DataTable.Colum ns(1).ColumnNam e to get
this info. You can just substitute it where I hard coded 1.

HTh,

Bill
"Strahimir Antoljak" <st***@netzero. net> wrote in message
news:Oi******** *****@TK2MSFTNG P10.phx.gbl...
Is it possible (and how?) to get the data grid column name
based on the DataGrid.Curren tCell?

The DataGrid has assigned a TableStyle comprising
selected columns (DataGridTextBo xColumn) from
the source DataTable (DataGrid.DataS ource=DataTable ).
I would like to be able to get the column name of the
datagrid based on the DataGrid current cell so I can reference
the appropriate column in the source DataTable.

Thanks,

--
Strah @ Langan


Nov 20 '05 #5

Thanks adamz5.... I am testing it right now,
looks good.

--
Strah @ Langan

"adamz5" <ad****@hotmail .com> wrote in message
news:40******** *************** ***@posting.goo gle.com...
use the mouse down event on the datagrid

and use System.Windows. Forms.DataGrid. HitTestInfo to get pos of column

something like:

objHitTest = Dgd.HitTest(e.X , e.Y)
Select Case objHitTest.Type
Case System.Windows. Forms.DataGrid. HitTestType.Cel l
strPartHit = "Cell"
Case System.Windows. Forms.DataGrid. HitTestType.Col umnHeader strPartHit = "ColumnHead er"
Case System.Windows. Forms.DataGrid. HitTestType.Col umnResize strPartHit = "Resize"
Case System.Windows. Forms.DataGrid. HitTestType.Cap tion
strPartHit = "Caption"
Case System.Windows. Forms.DataGrid. HitTestType.Par entRows
strPartHit = "ParentRows "
Case System.Windows. Forms.DataGrid. HitTestType.Row Header
strPartHit = "RowHeader"
If e.Clicks = 2 Then
'run your code here
End If
Case System.Windows. Forms.DataGrid. HitTestType.Row Resize
strPartHit = "RowResize"
Case System.Windows. Forms.DataGrid. HitTestType.Non e
strPartHit = "None"
Case Else
strPartHit = "Unknown"
End Select

from here get your currentrowindex

Nov 20 '05 #6
Cor,

this is not first time you helped me with elegant solutions.
It works like a charm. Many thanks.

--
Strah @ Langan

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:O6******** *****@TK2MSFTNG P09.phx.gbl...
Hi Strah,

Can you try this one (it is one long sentence)
Dim name As String =
DataGrid1.Table Styles(0).GridC olumnStyles(Dat aGrid1.CurrentC ell.ColumnNumbe r ).MappingName

I hope this works easy?

Cor

Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1868
by: PAUL GROSSMAN | last post by:
Hello everyone. I am working with a DataGrid using VB .Net (Windows Forms). I want to make one of the columns un-editable. I was able to do that by setting the .dsName.Tables("TblName").Columns("ColName").ReadOnly = True That made it so you can't change the value in the column, but you're still tabbing into the column (despite the fact you can't change it).
0
3190
by: Morné | last post by:
Hi how do I validate a text value in a datagrid e.g. the user is only allowed to type in a Y or a N. I specifically have a problem with using the PropertyDescriptorCollection. I get the following error: "Additional information: Cannot create a child list for field Query." Below my existing code:
2
2099
by: michael Schindler | last post by:
How i can set in a datagrid in c# widows forms in a specifig cell example Row 3 column 4 a specifig data for example "Michael"? I want after the user give in a cell in my datagrid additionally datas set in the same row but in a other column but automaticly. Is that possible an how I can realize that? thanks
11
5921
by: Junkguy | last post by:
I need some help programmatically causing a row in a DataGrid to "flush" its contents to its bound data (in Visual Studio 6 using Windows Forms with C#). My issue is I want to send an update to a database from a menu command while the user is editing a DataGrid. This is unusual in regard to examples and normal practice in that the cell of the DataGrid still has the focus. In all examples I can find, the user normally presses a button on...
2
9921
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell (multi-select without modifier keys). I got that working fine, but I also wanted to keep rows selected after a sort, which I do by storing the row's id in an arraylist. The idea was to do the sort and then go back and re-select the rows with that...
3
3027
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can download a fully working C# sample with the Northwind.mdb here: www.insightgis.com.au/web/stuff/DataGridCombo.zip
2
1262
by: Steph. | last post by:
Hi, I would like to get the Data of a given cell in the datagrid something like : MyStringVar = MyDataGrid.TableStyles.Cell.ToString(); But I can't find any way to read the data of a given cell, or row..... Any Idea ?
3
1580
by: tigerbalm via DotNetMonster.com | last post by:
Hallo! I have filled a datagrid with data from a database. I would like to edit the data in the datagrid and save it back to the database. My problem is that I don't really know how to capture the event of the cell that I am editing. The code below works but I would like to edit the data in a cell and then for example click a button and save it. Here is little of my code :
1
2743
by: Marre | last post by:
Hi all! I have made a datagrid on a winform and want to get the text out of the first cell when I have the row selected. Lets say I have a grid with som info and want to view more info about the selected row, how do I do that? Regards Marre
0
8668
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9014
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8855
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.