Q: Determing in a column in a datagrid

Discussion in 'Microsoft VB .NET' started by Geoff Jones, Nov 20, 2004.

  1. Geoff Jones

    Geoff Jones Guest

    Hi

    Can anybody tell me how to find the column index in a DataGrid knowing only
    the text in the column heading? Any sample code would be most useful.

    Thanks in advance

    Geoff
     
    Geoff Jones, Nov 20, 2004
    #1
    1. Advertisements

  2. Geoff Jones

    Cor Ligthert Guest

    Re: Determing in a column in a datagrid

    Geoff,

    With styles?

    When not than can it in my opinion be something as (depending on your
    datasource)
    \\\
    dim columnindex as integer
    for columnindex = 0 to dg.datasource.datatable.columns
    if datasource.datatable.columns(i).name = mytest
    exit for
    next
    ///
    I never did this, but just typed in this message as idea.

    Cor

    "Geoff Jones" <>

    > Hi
    >
    > Can anybody tell me how to find the column index in a DataGrid knowing
    > only
    > the text in the column heading? Any sample code would be most useful.
    >
    > Thanks in advance
    >
    > Geoff
    >
    >
     
    Cor Ligthert, Nov 20, 2004
    #2
    1. Advertisements

  3. Geoff Jones

    Geoff Jones Guest

    Re: Determing in a column in a datagrid

    Hi Cor

    I like the idea, unfortunately it does not work i.e. dg.datasource does not
    have a member "datatable".

    Geoff

    "Cor Ligthert" <> wrote in message
    news:%...
    > Geoff,
    >
    > With styles?
    >
    > When not than can it in my opinion be something as (depending on your
    > datasource)
    > \\\
    > dim columnindex as integer
    > for columnindex = 0 to dg.datasource.datatable.columns
    > if datasource.datatable.columns(i).name = mytest
    > exit for
    > next
    > ///
    > I never did this, but just typed in this message as idea.
    >
    > Cor
    >
    > "Geoff Jones" <>
    >
    > > Hi
    > >
    > > Can anybody tell me how to find the column index in a DataGrid knowing
    > > only
    > > the text in the column heading? Any sample code would be most useful.
    > >
    > > Thanks in advance
    > >
    > > Geoff
    > >
    > >

    >
    >
     
    Geoff Jones, Nov 20, 2004
    #3
  4. Geoff Jones

    Geoff Jones Guest

    Re: Determing in a column in a datagrid

    Hi again Cor

    You were, as always, on the right lines. Many thanks.

    All that was needed was a few minor changes to the code:

    Dim index As Integer
    For index=0 To dg.DataSource.Columns.Count - 1
    If dg.DataSource.Columns(index).ColumnName = mytestString Exit For
    Next

    i.e. The dg.DataSource returns a DataTable, in my case, so there is no need
    to use the DataTable part in the original code.

    Geoff

    "Geoff Jones" <> wrote in message
    news:419f5fc5$0$310$...
    > Hi Cor
    >
    > I like the idea, unfortunately it does not work i.e. dg.datasource does

    not
    > have a member "datatable".
    >
    > Geoff
    >
    > "Cor Ligthert" <> wrote in message
    > news:%...
    > > Geoff,
    > >
    > > With styles?
    > >
    > > When not than can it in my opinion be something as (depending on your
    > > datasource)
    > > \\\
    > > dim columnindex as integer
    > > for columnindex = 0 to dg.datasource.datatable.columns
    > > if datasource.datatable.columns(i).name = mytest
    > > exit for
    > > next
    > > ///
    > > I never did this, but just typed in this message as idea.
    > >
    > > Cor
    > >
    > > "Geoff Jones" <>
    > >
    > > > Hi
    > > >
    > > > Can anybody tell me how to find the column index in a DataGrid knowing
    > > > only
    > > > the text in the column heading? Any sample code would be most useful.
    > > >
    > > > Thanks in advance
    > > >
    > > > Geoff
    > > >
    > > >

    > >
    > >

    >
    >
     
    Geoff Jones, Nov 20, 2004
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dsa

    determing when form has stopped moving

    dsa, Feb 28, 2004, in forum: Microsoft VB .NET
    Replies:
    1
    Views:
    152
    Klaus Löffelmann
    Feb 28, 2004
  2. RD

    Determing internal format of file

    RD, Jul 31, 2004, in forum: Microsoft VB .NET
    Replies:
    2
    Views:
    131
    Oenone
    Aug 2, 2004
  3. Moondog
    Replies:
    8
    Views:
    1,639
    Moondog
    Sep 23, 2004
  4. RD

    Determing a quarter in a financial year

    RD, Oct 31, 2004, in forum: Microsoft VB .NET
    Replies:
    3
    Views:
    168
    Cor Ligthert
    Oct 31, 2004
  5. Ron

    determing what item in combobox is selected?

    Ron, Feb 2, 2007, in forum: Microsoft VB .NET
    Replies:
    1
    Views:
    164
    Stephany Young
    Feb 2, 2007
Loading...

Share This Page