473,320 Members | 1,861 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,320 software developers and data experts.

DataGrid Colum Names

I have an application in which it would be VERY beneficial if I could obtain
the names of the colums in a datagrid.

For example

dim datagrid1 as new datagrid
datagrid1.datasource = (stored procedure that loads datagrid)
datagrid1.databind()

I am able to obtain the data in the datagrid by its relative number however
I can't figure out how to get the names and in this application they may
change over time.

Any help would be GREATLY appreciated!

Thanks,

Fred
Nov 20 '05 #1
11 1665
If it's bound to a grid, then the grid column should correspond with the
columns in the underlying datatable. As such, you can interrogate the
DataTable's column's collection and just lookup the ColumnName property ie
DataTable.Columns[0].ColumnName;

HTH,

bill
"Fred Nelson" <fr**@smartybird.com> wrote in message
news:OW**************@TK2MSFTNGP09.phx.gbl...
I have an application in which it would be VERY beneficial if I could obtain the names of the colums in a datagrid.

For example

dim datagrid1 as new datagrid
datagrid1.datasource = (stored procedure that loads datagrid)
datagrid1.databind()

I am able to obtain the data in the datagrid by its relative number however I can't figure out how to get the names and in this application they may
change over time.

Any help would be GREATLY appreciated!

Thanks,

Fred

Nov 20 '05 #2
Bill:

Thanks for your reply - it looks like I may get this to work!

I don't understand one thing - in the example that I provided I bound the
data grid to a class library with a stored procedure that loaded it. I'm
unclear how to reference the underlying data table in this example where
datagrid1 contains the data.

DataGrid1.Colums[0].ColumnName is not valid syntax -

Do I need to create a data table from the stored procedure rather than a
data grid - or is there something I'm missing?

Thanks again for your help!

Fred
"William Ryan eMVP" <bi**@NoSp4m.devbuzz.com> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl...
If it's bound to a grid, then the grid column should correspond with the
columns in the underlying datatable. As such, you can interrogate the
DataTable's column's collection and just lookup the ColumnName property ie
DataTable.Columns[0].ColumnName;

HTH,

bill
"Fred Nelson" <fr**@smartybird.com> wrote in message
news:OW**************@TK2MSFTNGP09.phx.gbl...
I have an application in which it would be VERY beneficial if I could

obtain
the names of the colums in a datagrid.

For example

dim datagrid1 as new datagrid
datagrid1.datasource = (stored procedure that loads datagrid)
datagrid1.databind()

I am able to obtain the data in the datagrid by its relative number

however
I can't figure out how to get the names and in this application they may
change over time.

Any help would be GREATLY appreciated!

Thanks,

Fred


Nov 20 '05 #3
Fred:

You'll reference the DataTable that you bound the grid to. Whatever it's
name is, reference it. How it got filled (ie Stored Proc) doesn't matter.
Depending on how you called DataAdapter.Fill, you may want to use the
Numeric Index of hte Tables collection ie
myDataSet.Tables[0].Columns[0].ColumnName;

conceptually, focus on hitting the datasource with wahtever you want. The
grid is just the presentation of the underlying data obejct. On the Web,
changes won't necessarily be reflected visibly until a postback occurs, but
on the desktop, as soon as you change the underlying table value
programmatically, the change will be visible in the Grid immediately.

HTH,

Bill
"Fred Nelson" <fr**@smartybird.com> wrote in message
news:eT**************@TK2MSFTNGP10.phx.gbl...
Bill:

Thanks for your reply - it looks like I may get this to work!

I don't understand one thing - in the example that I provided I bound the
data grid to a class library with a stored procedure that loaded it. I'm
unclear how to reference the underlying data table in this example where
datagrid1 contains the data.

DataGrid1.Colums[0].ColumnName is not valid syntax -

Do I need to create a data table from the stored procedure rather than a
data grid - or is there something I'm missing?

Thanks again for your help!

Fred
"William Ryan eMVP" <bi**@NoSp4m.devbuzz.com> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl...
If it's bound to a grid, then the grid column should correspond with the
columns in the underlying datatable. As such, you can interrogate the
DataTable's column's collection and just lookup the ColumnName property ie DataTable.Columns[0].ColumnName;

HTH,

bill
"Fred Nelson" <fr**@smartybird.com> wrote in message
news:OW**************@TK2MSFTNGP09.phx.gbl...
I have an application in which it would be VERY beneficial if I could

obtain
the names of the colums in a datagrid.

For example

dim datagrid1 as new datagrid
datagrid1.datasource = (stored procedure that loads datagrid)
datagrid1.databind()

I am able to obtain the data in the datagrid by its relative number

however
I can't figure out how to get the names and in this application they may change over time.

Any help would be GREATLY appreciated!

Thanks,

Fred



Nov 20 '05 #4
Bill:

Thanks for your quick answer - I really appreciate it!

I am a newby and so I'm confused about the reply that you gave. I have
loaded my datagrid with the following:

dim myproclib as new datafunctions.datalib

dim datagrid1 as new datagrid
datagrid1.datasource = myproclib.getstates
datagrid1.databind()

So I haven't (or I think I haven't) created a data table and then bound the
grid to it. Should I create a datatable from the stored procedure? If I
create one then can I populate it without knowing the column names I will
receive?

Again, thanks for your help!

Fred

"William Ryan eMVP" <bi**@NoSp4m.devbuzz.com> wrote in message
news:Or**************@TK2MSFTNGP11.phx.gbl...
Fred:

You'll reference the DataTable that you bound the grid to. Whatever it's
name is, reference it. How it got filled (ie Stored Proc) doesn't matter.
Depending on how you called DataAdapter.Fill, you may want to use the
Numeric Index of hte Tables collection ie
myDataSet.Tables[0].Columns[0].ColumnName;

conceptually, focus on hitting the datasource with wahtever you want. The
grid is just the presentation of the underlying data obejct. On the Web,
changes won't necessarily be reflected visibly until a postback occurs, but on the desktop, as soon as you change the underlying table value
programmatically, the change will be visible in the Grid immediately.

HTH,

Bill
"Fred Nelson" <fr**@smartybird.com> wrote in message
news:eT**************@TK2MSFTNGP10.phx.gbl...
Bill:

Thanks for your reply - it looks like I may get this to work!

I don't understand one thing - in the example that I provided I bound the
data grid to a class library with a stored procedure that loaded it. I'm unclear how to reference the underlying data table in this example where
datagrid1 contains the data.

DataGrid1.Colums[0].ColumnName is not valid syntax -

Do I need to create a data table from the stored procedure rather than a
data grid - or is there something I'm missing?

Thanks again for your help!

Fred
"William Ryan eMVP" <bi**@NoSp4m.devbuzz.com> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl...
If it's bound to a grid, then the grid column should correspond with the columns in the underlying datatable. As such, you can interrogate the
DataTable's column's collection and just lookup the ColumnName property
ie DataTable.Columns[0].ColumnName;

HTH,

bill
"Fred Nelson" <fr**@smartybird.com> wrote in message
news:OW**************@TK2MSFTNGP09.phx.gbl...
> I have an application in which it would be VERY beneficial if I
could obtain
> the names of the colums in a datagrid.
>
> For example
>
> dim datagrid1 as new datagrid
> datagrid1.datasource = (stored procedure that loads datagrid)
> datagrid1.databind()
>
> I am able to obtain the data in the datagrid by its relative number
however
> I can't figure out how to get the names and in this application they

may > change over time.
>
> Any help would be GREATLY appreciated!
>
> Thanks,
>
> Fred
>
>



Nov 20 '05 #5
Hi Fred,

On the winforms version, you can't bind to a DataReader at all like you can
in ASP.NET which tells you something...

Can it be that your datasource is a datareader?

Than the name of your column can be
Dim William As String = rdr.GetName(0)

(And I wished Bill saw my face when I wrote this and this is the true
situation, however that is between me and him and only fun of course)

And Fred, if this is not clear, feel free to ask further I think we where on
the wrong road.

I hope this helps?

Cor.
Nov 20 '05 #6
Cor:

Thanks for your reply - and patience with me - I'm new to this and it will
be worth it when I learn it!!!!

I'm still lost - the code I'm using is as follows

----
dim myproclib as new datafunctions.datalib

dim datagrid1 as new datagrid
datagrid1.datasource = myproclib.getstates (this is a class lib that
calles a stored procedure)
datagrid1.databind()
-----

So I don't think I'm using a data reader or binding.

So: Given the datagrid - is there any way to get the column names?

If I need to build a data table then I assume there is another step?

Thanks,

Fred
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi Fred,

On the winforms version, you can't bind to a DataReader at all like you can in ASP.NET which tells you something...

Can it be that your datasource is a datareader?

Than the name of your column can be
Dim William As String = rdr.GetName(0)

(And I wished Bill saw my face when I wrote this and this is the true
situation, however that is between me and him and only fun of course)

And Fred, if this is not clear, feel free to ask further I think we where on the wrong road.

I hope this helps?

Cor.

Nov 20 '05 #7
Hi Fred,

Can you add this to your after that databind
dim datagrid1 as new datagrid
datagrid1.datasource = myproclib.getstates (this is a class lib that
calles a stored procedure)
datagrid1.databind()


Dim a As String = DataGrid1.DataSource.ToString

And than see in the debugger what is the datasource?

Cor



Nov 20 '05 #8
Coor:

There is no .ToString method - I get a crash:

"Cast from type SqlDataReader to Type String is not valid"

Fred
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi Fred,

Can you add this to your after that databind
dim datagrid1 as new datagrid
datagrid1.datasource = myproclib.getstates (this is a class lib that
calles a stored procedure)
datagrid1.databind()


Dim a As String = DataGrid1.DataSource.ToString

And than see in the debugger what is the datasource?

Cor


Nov 20 '05 #9
Hi Fred,

This is weird, I tested it in advance and it did work, however in my
opinion it can be that it shows that your datasource is a datareader and
than you can try my suggestion.

Cor
Coor:
There is no .ToString method - I get a crash:
"Cast from type SqlDataReader to Type String is not valid"

Nov 20 '05 #10
Cor:

I'm not clear - given my code as follows what exactly am I to do?

dim datagrid1 as new datagrid
datagrid1.datasource = myproclib.getstates
datagrid1.databind()

Thanks again,

Fred
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
Hi Fred,

This is weird, I tested it in advance and it did work, however in my
opinion it can be that it shows that your datasource is a datareader and
than you can try my suggestion.

Cor
Coor:
There is no .ToString method - I get a crash:
"Cast from type SqlDataReader to Type String is not valid"


Nov 20 '05 #11
Hi Fred,

I cannot see what is in this hidden class, however because it is probably a
reader what is given back, you could try

dim datagrid1 as new datagrid
datagrid1.datasource = myproclib.getstates
datagrid1.databind()
Dim Myfirstcolumn As String = myproclib.GetName(0)

However probably it fails and than is because much classbuilders say the
user has nothing to know about the class, and are very strict in that. Than
is the only thing to go back to the one who made that procedure.

Cor
Nov 20 '05 #12

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

Similar topics

0
by: Shail | last post by:
Hello every one I am using editable datagrid in my application. I set grid's allowpaging property to true. My application is not working properly. When I click on 'Edit' to modify any row, instead...
0
by: Eric | last post by:
Hello, I have a datagrid with sorting enabled. When clickong on the colum names in the header the datagrid is sorted no problem. Unfortunatly, I have a graph that needs to be generated for each...
7
by: Kenneth P | last post by:
Hi, I have an asp.net application where I calculate things and show the result in a datagrid object. The grid needs 21 columns to show all information needed for persons to understand the whole...
2
by: Fred Nelson | last post by:
I have an application in which it would be VERY beneficial if I could obtain the names of the colums in a datagrid. For example dim datagrid1 as new datagrid datagrid1.datasource = (stored...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
3
by: Bill Nguyen | last post by:
I found that rows in datagrid can be sorted by clicking on the column header. However, this doesn't refresh the .currentindex DataGrid1.CurrentCell.RowNumber I need either to disable colum...
5
by: mail | last post by:
Urgent help needed! I moved an application from ASP+ACCESS to ASP+MS SQLSERVER and I have the following problem: If the join on two tables results on duplicate colum names (which appear in...
0
by: abatur | last post by:
I want to convert image colum to use in crystal report. I used following SQL view: Select dbo.names.Fullname, CONVERT(varchar(8000), CONVERT(binary(8000), dbo.names.DTLINFO)) as DTLUSRINFO from...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.