PC Review


Reply
Thread Tools Rate Thread

DataGrid Column By Text

 
 
Mr.D
Guest
Posts: n/a
 
      20th Oct 2004
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2hhcmxpZQ==?=
Guest
Posts: n/a
 
      21st Oct 2004
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).GridColumnStyles
_(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
>
>
>

 
Reply With Quote
 
Mr.D
Guest
Posts: n/a
 
      21st Oct 2004
"Charlie" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid Column Text =?Utf-8?B?TGkgUGFuZw==?= Microsoft VB .NET 5 16th Dec 2005 04:58 AM
Text cut-off in column of DataGrid rpy@hotmail.com Microsoft Dot NET Compact Framework 1 22nd Mar 2005 12:34 AM
Datagrid Column Header Text Demetri Microsoft ASP .NET 0 21st Apr 2004 08:03 PM
DataGrid text box column neil rowe Microsoft VB .NET 1 6th Dec 2003 10:32 PM
Finding TEXT of DataGrid Column David Elliott Microsoft Dot NET Framework Forms 1 21st Aug 2003 01:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:58 AM.