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

Simple Question - Datagrid and Typed dataset

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
13 1829
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
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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Latten | last post by:
Hi there, I have got a problem when adding extra (= dummy) columns to a datagrid. I have a datagrid that is bound to a datatable. The datatable is filled with data from a SQL Server 2000...
0
by: Frosty | last post by:
Hi I am using the VS xsd designer to create a strongly typed dataset. The dataset is apparently successfully created, with no warnings or errors given. Is it not then to be expected that this...
1
by: J | last post by:
Situation - Using the table pubs.titleauthor in a strongly typed dataset, attached to a datagrid, using the datagrid I would like to set the royaltyper field = null (the database allows nulls in...
3
by: Kevin | last post by:
Hi Al I want to add two combobox columns in my datagrid. the one combobox column must be bound to the same datasource that the datagrid is, and the other combobox I just want to populate with a...
2
by: Frosty | last post by:
Howto make datagrid enforce rules of xml schema? Created xml schema in the designer. Constraints created there using the following <xs:simpleType name="zipcode"><xs:restriction...
7
by: Pierluigi Terzoli | last post by:
Hi everybody, I need help for this problem: I'm using a DataGrid to Insert/Modify/Cancel data from a single table. At the moment, every cell modification of a pre-existing row is correctly update...
12
by: Daniel Walzenbach | last post by:
Hi, I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the...
2
by: Bennett Haselton | last post by:
I know how to create a DataAdapter that loads data from a data source into a table in a typed DataSet, and how to set the DataSource and DataMember properties of a DataGrid so that at run time it...
5
by: antonyliu2002 | last post by:
I want to put results from more than 1 sql queries into a signle datagrid, For example, in my web application, I submit this following query to my oracle database: Select NetID, Firstname,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.