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

DataGrid Column By Text

I know that it is possible to do this: MsgBox(DataGrid1.Item(rowIndex,
columnIndex))
However my data has several columns wich I dont controll.
Ex: Name, Adress, Favorite Food in different orders.

So how do I select column by Text instead of number?
EX: DataGrid1.Item(rowIndex, DataGrid1.Column("Adress")

Hope that I made myself understandable ;)

----
Tim
Nov 21 '05 #1
2 1266
Datagrids in .net seem kind of convoluted at first.

Here is some code that shows how the grid is built from the ground up, as a
set of objects:

Put a datagrid on a form.

This goes in the forms load event:

Dim DT As New DataTable()
DT.Columns.Add(New DataColumn("Fieldname1"))
DT.Columns.Add(New DataColumn("Fieldname2"))
Dim DR As DataRow = DT.NewRow
DR.Item(0) = "John"
DR.Item(1) = "Doe"
DT.Rows.Add(DR)

Dim ts As New DataGridTableStyle()
Dim dgc(1) As DataGridColumnStyle
dgc(0) = New DataGridTextBoxColumn()
dgc(0).HeaderText = "Col 1"
dgc(0).MappingName = "Fieldname1"
dgc(1) = New DataGridTextBoxColumn()
dgc(1).HeaderText = "Col 2"
dgc(1).MappingName = "Fieldname2"
ts.GridColumnStyles.AddRange(dgc)

Me.DataGrid1.TableStyles.Add(ts)
Me.DataGrid1.DataSource = DT

Then add a Datagrid CurrentCellChanged event handler:

Private Sub DataGrid1_CellChanged(ByVal sender As System.Object, _
ByVal e As EventArgs) Handles DataGrid1.CurrentCellChanged
MessageBox.Show(DataGrid1.TableStyles(0).GridColum nStyles
_(DataGrid1.CurrentCell.ColumnNumber).HeaderText)

End Sub
Note:
Dim dgc(1) As DataGridColumnStyle--
This declaration is made of the base class, which is abstract. This allows
you to instantiate each column as a text column, or a boolean column, or as
another style that you derive from the base class.
"Mr.D" wrote:
I know that it is possible to do this: MsgBox(DataGrid1.Item(rowIndex,
columnIndex))
However my data has several columns wich I dont controll.
Ex: Name, Adress, Favorite Food in different orders.

So how do I select column by Text instead of number?
EX: DataGrid1.Item(rowIndex, DataGrid1.Column("Adress")

Hope that I made myself understandable ;)

----
Tim

Nov 21 '05 #2
"Charlie" <Ch*****@discussions.microsoft.com> wrote
[code]


I get my data from the Internet, So I dont have any control of the data
layout.

<code>
Dim dsPubs As New Data.DataSet
Dim xdcDOC As New Xml.XmlDocument

dsPubs.ReadXml(http://www......)
DataGrid1.DataMember = "Name"
DataGrid1.DataSource = dsPubs
</code>

So how do I get the columnIndex of the column with the text "Adress"

----
Tim
Nov 21 '05 #3

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

Similar topics

3
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...
3
by: Doug | last post by:
Hi I have the following code (not mine) that populates a datagrid with some file names. But I want to replace the datagrid with a combo box. private void OnCurrentDataCellChanged(object sender,...
9
by: Paul | last post by:
Hi I have a data grid with a hyperlink column. the colum has numbers like 00001,000002, ect. Just wondering how to get the text value of the cell as tempstring =...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
1
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
3
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I...
8
by: Matt | last post by:
Guys I could really use some help with this. I think that it's probably a simple solution but I haven't been able to find anything. I have a datagrid on my form that I populate via code like...
3
by: rn5a | last post by:
A DataGrid has the following TemplateColumn: <asp:DataGrid ID="dgCart"...OnSortCommand="SortGrid" AllowSorting="true"....> <Column> <asp:TemplateColumn HeaderImageUrl="Images\Up.gif"...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
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:
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,...
0
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...

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.