By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,422 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,422 IT Pros & Developers. It's quick & easy.

Simple Question - Datagrid and Typed dataset

P: n/a
I did a lot of searches and read something about
datagrids. But I couldn't find the answer of my simple
question, how can I show only my desired columns of
a table? for example I wrote this sql query:

OleDbDataAdapter1.SelectCommand.CommandText = & _
"Select illNameE From tblIllness"
OleDbDataAdapter1.Fill(DsIllness1)

But in my datagrid, I get (null) for other ccolumns instead
of hiding undesired columns.

Another question: Is datagrid best choice in windows form
to show a list of "clickable" data?

TIA
--
Saber S.
http://maghalat.com
Nov 21 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
I'm speculating that you are referring to situations where you pull more
than one column of data.

You could simply not Select those columns in your query.

But if you do, you could use MappingType.Hidden to hide those in the grid:

ds.Tables("dtCosts").Columns("SalesID").ColumnMapp ing = MappingType.Hidden

"Saber" <saber[.AT.]oxin.ir> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I did a lot of searches and read something about
datagrids. But I couldn't find the answer of my simple
question, how can I show only my desired columns of
a table? for example I wrote this sql query:

OleDbDataAdapter1.SelectCommand.CommandText = & _
"Select illNameE From tblIllness"
OleDbDataAdapter1.Fill(DsIllness1)

But in my datagrid, I get (null) for other ccolumns instead
of hiding undesired columns.

Another question: Is datagrid best choice in windows form
to show a list of "clickable" data?

TIA
--
Saber S.
http://maghalat.com

Nov 21 '05 #2

P: n/a
With a datagrid, if you set the column width of the columns you want hidden
to 0 or you can just not provide a ColumnMapping for them. Check out this
class http://www.knowdotnet.com/articles/cgrid.html - the code that's
included with it will show you how to do most anything you will want to do
with a grid.. There's also a NullText property you can set for each Column
that has DataGridColumnStyle that will substitute the value you specify
instead of showing (Null) although frm the sound of yoru entire question,
you don't want a value there, you want the column hidden.

Anyway, as far as 'best' goes, that depends on a lot of things but as far as
a 'list of clickable data', actually, the grid probably isnt' that great of
a choice. Out of the box it has sorting capabilities, but if you bind to a
DataView instead of a DataTable, it's easy enough to implement through code.
The reason I say this is b/c if you only have one column in a list, the grid
has a lot of extra hoops you need to jump through to get a given value that
a ListBox or ComboBox doesn't (not that I'm saying it's 'hard', I just think
that for clickable funcionality in a list - that the ListBox or ComboBox is
probably a better choice in most cases. A Listbox is probably a better
choice for a single column list b/c you can just reference what they click
with SelectedItem and SelectedValue (remember to set the DisplayMember and
ValueMembers - this way, you can show one value but use a different one -
something which is a pain to do in a grid)
"Saber" <saber[.AT.]oxin.ir> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I did a lot of searches and read something about
datagrids. But I couldn't find the answer of my simple
question, how can I show only my desired columns of
a table? for example I wrote this sql query:

OleDbDataAdapter1.SelectCommand.CommandText = & _
"Select illNameE From tblIllness"
OleDbDataAdapter1.Fill(DsIllness1)

But in my datagrid, I get (null) for other ccolumns instead
of hiding undesired columns.

Another question: Is datagrid best choice in windows form
to show a list of "clickable" data?

TIA
--
Saber S.
http://maghalat.com

Nov 21 '05 #3

P: n/a
Thanks Earl,
As I said before, if I don't select those columns in query, I get
columns with (null) text instead of hidden columns.
But MappingType.Hidden is good for me, Thanks for that.

--
Saber S.
http://maghalat.com
"Earl" <br******@newsgroups.nospam> wrote in message
news:Oi**************@TK2MSFTNGP10.phx.gbl...
I'm speculating that you are referring to situations where you pull more
than one column of data.

You could simply not Select those columns in your query.

But if you do, you could use MappingType.Hidden to hide those in the grid:

ds.Tables("dtCosts").Columns("SalesID").ColumnMapp ing = MappingType.Hidden

"Saber" <saber[.AT.]oxin.ir> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I did a lot of searches and read something about
datagrids. But I couldn't find the answer of my simple
question, how can I show only my desired columns of
a table? for example I wrote this sql query:

OleDbDataAdapter1.SelectCommand.CommandText = & _
"Select illNameE From tblIllness"
OleDbDataAdapter1.Fill(DsIllness1)

But in my datagrid, I get (null) for other ccolumns instead
of hiding undesired columns.

Another question: Is datagrid best choice in windows form
to show a list of "clickable" data?

TIA
--
Saber S.
http://maghalat.com


Nov 21 '05 #4

P: n/a
Thanks for your complete and precise answer.

Just in some cases I need to hide columns and the default
view includes all columns or more than one column.
alhtough, there is a multi-column list box anc combox I can
use as an alternative:
http://www.codeproject.com/cs/combob...umnlistbox.asp
http://www.codeproject.com/vb/net/Mu...nFlatCombo.asp

--
Saber S.
http://maghalat.com

"W.G. Ryan MVP" <Wi*********@nospam.gmail.com> wrote in message
news:Oa****************@TK2MSFTNGP10.phx.gbl...
With a datagrid, if you set the column width of the columns you want
hidden to 0 or you can just not provide a ColumnMapping for them. Check
out this class http://www.knowdotnet.com/articles/cgrid.html - the code
that's included with it will show you how to do most anything you will
want to do with a grid.. There's also a NullText property you can set for
each Column that has DataGridColumnStyle that will substitute the value
you specify instead of showing (Null) although frm the sound of yoru
entire question, you don't want a value there, you want the column hidden.

Anyway, as far as 'best' goes, that depends on a lot of things but as far
as a 'list of clickable data', actually, the grid probably isnt' that
great of a choice. Out of the box it has sorting capabilities, but if you
bind to a DataView instead of a DataTable, it's easy enough to implement
through code. The reason I say this is b/c if you only have one column in
a list, the grid has a lot of extra hoops you need to jump through to get
a given value that a ListBox or ComboBox doesn't (not that I'm saying it's
'hard', I just think that for clickable funcionality in a list - that the
ListBox or ComboBox is probably a better choice in most cases. A Listbox
is probably a better choice for a single column list b/c you can just
reference what they click with SelectedItem and SelectedValue (remember to
set the DisplayMember and ValueMembers - this way, you can show one value
but use a different one - something which is a pain to do in a grid)
"Saber" <saber[.AT.]oxin.ir> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I did a lot of searches and read something about
datagrids. But I couldn't find the answer of my simple
question, how can I show only my desired columns of
a table? for example I wrote this sql query:

OleDbDataAdapter1.SelectCommand.CommandText = & _
"Select illNameE From tblIllness"
OleDbDataAdapter1.Fill(DsIllness1)

But in my datagrid, I get (null) for other ccolumns instead
of hiding undesired columns.

Another question: Is datagrid best choice in windows form
to show a list of "clickable" data?

TIA
--
Saber S.
http://maghalat.com


Nov 21 '05 #5

P: n/a
What's wrong here?

DsIllness1.tblIllness.illIDColumn.ColumnMapping = MappingType.Hidden
DsIllness1.tblIllness.illDescColumn.ColumnMapping = MappingType.Hidden
OleDbDataAdapter1.Fill(DsIllness1)

Datagrid shows illDescColumn and illIDColumn yet :(

--
Saber S.
http://maghalat.com
"Saber" <saber[.AT.]oxin.ir> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I did a lot of searches and read something about
datagrids. But I couldn't find the answer of my simple
question, how can I show only my desired columns of
a table? for example I wrote this sql query:

OleDbDataAdapter1.SelectCommand.CommandText = & _
"Select illNameE From tblIllness"
OleDbDataAdapter1.Fill(DsIllness1)

But in my datagrid, I get (null) for other ccolumns instead
of hiding undesired columns.

Another question: Is datagrid best choice in windows form
to show a list of "clickable" data?

TIA
--
Saber S.
http://maghalat.com

Nov 21 '05 #6

P: n/a
You can't hide something you haven't filled yet.

"Saber" <saber[.AT.]oxin.ir> wrote in message
news:ON**************@TK2MSFTNGP10.phx.gbl...
What's wrong here?

DsIllness1.tblIllness.illIDColumn.ColumnMapping = MappingType.Hidden
DsIllness1.tblIllness.illDescColumn.ColumnMapping = MappingType.Hidden
OleDbDataAdapter1.Fill(DsIllness1)

Datagrid shows illDescColumn and illIDColumn yet :(

--
Saber S.
http://maghalat.com
"Saber" <saber[.AT.]oxin.ir> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I did a lot of searches and read something about
datagrids. But I couldn't find the answer of my simple
question, how can I show only my desired columns of
a table? for example I wrote this sql query:

OleDbDataAdapter1.SelectCommand.CommandText = & _
"Select illNameE From tblIllness"
OleDbDataAdapter1.Fill(DsIllness1)

But in my datagrid, I get (null) for other ccolumns instead
of hiding undesired columns.

Another question: Is datagrid best choice in windows form
to show a list of "clickable" data?

TIA
--
Saber S.
http://maghalat.com


Nov 21 '05 #7

P: n/a
But the last line of code fills:
OleDbDataAdapter1.Fill(DsIllness1)
--
Saber S.
http://maghalat.com
"Earl" <br******@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
You can't hide something you haven't filled yet.

"Saber" <saber[.AT.]oxin.ir> wrote in message
news:ON**************@TK2MSFTNGP10.phx.gbl...
What's wrong here?

DsIllness1.tblIllness.illIDColumn.ColumnMapping = MappingType.Hidden
DsIllness1.tblIllness.illDescColumn.ColumnMapping = MappingType.Hidden
OleDbDataAdapter1.Fill(DsIllness1)

Datagrid shows illDescColumn and illIDColumn yet :(

--
Saber S.
http://maghalat.com

Nov 21 '05 #8

P: n/a
da.Fill(ds, "dtCosts")

ds.Tables("dtCosts").Columns("SalesID").ColumnMapp ing = MappingType.Hidden
ds.Tables("dtCosts").Columns("LaborCostsID").Colum nMapping =
MappingType.Hidden
....

"Saber" <saber[.AT.]oxin.ir> wrote in message
news:eV**************@TK2MSFTNGP14.phx.gbl...
But the last line of code fills:
OleDbDataAdapter1.Fill(DsIllness1)
--
Saber S.
http://maghalat.com
"Earl" <br******@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
You can't hide something you haven't filled yet.

"Saber" <saber[.AT.]oxin.ir> wrote in message
news:ON**************@TK2MSFTNGP10.phx.gbl...
What's wrong here?

DsIllness1.tblIllness.illIDColumn.ColumnMapping = MappingType.Hidden
DsIllness1.tblIllness.illDescColumn.ColumnMapping = MappingType.Hidden
OleDbDataAdapter1.Fill(DsIllness1)

Datagrid shows illDescColumn and illIDColumn yet :(

--
Saber S.
http://maghalat.com


Nov 21 '05 #9

P: n/a
It is untyped dataset, what about typed dataset?
I've no DataTable.
--
Saber S.
http://maghalat.com
"Earl" <br******@newsgroups.nospam> wrote in message
news:Ou*************@TK2MSFTNGP15.phx.gbl...
da.Fill(ds, "dtCosts")

ds.Tables("dtCosts").Columns("SalesID").ColumnMapp ing = MappingType.Hidden
ds.Tables("dtCosts").Columns("LaborCostsID").Colum nMapping =
MappingType.Hidden
...

"Saber" <saber[.AT.]oxin.ir> wrote in message
news:eV**************@TK2MSFTNGP14.phx.gbl...
But the last line of code fills:
OleDbDataAdapter1.Fill(DsIllness1)
--
Saber S.
http://maghalat.com
"Earl" <br******@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
You can't hide something you haven't filled yet.

"Saber" <saber[.AT.]oxin.ir> wrote in message
news:ON**************@TK2MSFTNGP10.phx.gbl...
What's wrong here?

DsIllness1.tblIllness.illIDColumn.ColumnMapping = MappingType.Hidden
DsIllness1.tblIllness.illDescColumn.ColumnMapping = MappingType.Hidden
OleDbDataAdapter1.Fill(DsIllness1)

Datagrid shows illDescColumn and illIDColumn yet :(

--
Saber S.
http://maghalat.com



Nov 21 '05 #10

P: n/a
Saber,

Did you try it,

A typed dataset inherits from an untyped dataset

It tells by instance that the property 'ds.dtCosts' is the same as
'ds.Tables("dtCosts")'

I hope this helps,

Cor
Nov 21 '05 #11

P: n/a
Ok, I did both of those methods, but still see the columns.

--
Saber S.
http://maghalat.com
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:uE**************@TK2MSFTNGP09.phx.gbl...
Saber,

Did you try it,

A typed dataset inherits from an untyped dataset

It tells by instance that the property 'ds.dtCosts' is the same as
'ds.Tables("dtCosts")'

I hope this helps,

Cor

Nov 21 '05 #12

P: n/a
Saber,

I was only answering on your reply about typed and untyped dataset.

However, have a look at this sample on our website.

http://www.windowsformsdatagridhelp....3-a3539697edbd

And than this sentence
dt.Columns("USA").ColumnMapping = MappingType.Hidden

(in your typed dataset you could first do)
dim dt as datatable = MyDataSet.Mytable

There is more about this on our website.

I hope this helps,

Cor
Nov 21 '05 #13

P: n/a
Thanks Earl and Cor,
It has been done by using a DataTable instead of Dataset:
Dim dt As New DataTable
OleDbDataAdapter1.Fill(dt)
dt.Columns("illID").ColumnMapping = MappingType.Hidden
dg.DataSource = dt.DefaultView

I don't know it is a good method or not, but it works..
--
Saber S.
http://maghalat.com
"Saber" <saber[.AT.]oxin.ir> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
I did a lot of searches and read something about
datagrids. But I couldn't find the answer of my simple
question, how can I show only my desired columns of
a table? for example I wrote this sql query:

OleDbDataAdapter1.SelectCommand.CommandText = & _
"Select illNameE From tblIllness"
OleDbDataAdapter1.Fill(DsIllness1)

But in my datagrid, I get (null) for other ccolumns instead
of hiding undesired columns.

Another question: Is datagrid best choice in windows form
to show a list of "clickable" data?

TIA
--
Saber S.
http://maghalat.com

Nov 21 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.