473,387 Members | 1,290 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.

trouble with a datagridview and a column hided

hi all

I m using the visual studio designer to create 1 Dataset with 1 table
with 3 columns : Id, Name, Birthday.

Once this done, still with the designer, I m creating a datagridview
and choose my dataset as DataSource.

magic : the columns appear in the datagridview.

Still with the designer, I can change the properties of the fist column
"Id" to hide it.

now it s time to write some code :
on the cellClick event I want to get the value of the Id, unfortunaly
it throws an exception cause the column is hided

DataGridViewRow row =
(DataGridViewRow)dataGridView.Rows[e.RowIndex];

if (row != null)
{
try
{
this.selectedRowIndex =
(int)row.Cells["Id"].Value;
}
catch
{
int a = 1;
}
}

Does anyone know how to get the value of a hiding column when the user
clics on a row ?

thx for your help

ben

Nov 14 '06 #1
3 1530
Hi Ben,

IIRC, your code should work if you really did hide the column.

By removing the column from the list in the designer you're not hiding the
column - you're completely removing it from the collection.

You must set Visible = false instead.

--
Dave Sexton

"finleeds" <fi******@hotmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
hi all

I m using the visual studio designer to create 1 Dataset with 1 table
with 3 columns : Id, Name, Birthday.

Once this done, still with the designer, I m creating a datagridview
and choose my dataset as DataSource.

magic : the columns appear in the datagridview.

Still with the designer, I can change the properties of the fist column
"Id" to hide it.

now it s time to write some code :
on the cellClick event I want to get the value of the Id, unfortunaly
it throws an exception cause the column is hided

DataGridViewRow row =
(DataGridViewRow)dataGridView.Rows[e.RowIndex];

if (row != null)
{
try
{
this.selectedRowIndex =
(int)row.Cells["Id"].Value;
}
catch
{
int a = 1;
}
}

Does anyone know how to get the value of a hiding column when the user
clics on a row ?

thx for your help

ben

Nov 14 '06 #2
many thanks for your quick answer
but it s what I did :
//
// idDataGridViewTextBoxColumn
//
this.idDataGridViewTextBoxColumn.DataPropertyName = "Id";
this.idDataGridViewTextBoxColumn.HeaderText = "Id";
this.idDataGridViewTextBoxColumn.Name =
"idDataGridViewTextBoxColumn";
this.idDataGridViewTextBoxColumn.Visible = false;

and It still does not work :(

I wrote a very small project to reproduce this problem, I could send it
to you if you want ?

I ll take all advice or ideas :))

ben

Dave Sexton a écrit :
Hi Ben,

IIRC, your code should work if you really did hide the column.

By removing the column from the list in the designer you're not hiding the
column - you're completely removing it from the collection.

You must set Visible = false instead.

--
Dave Sexton

"finleeds" <fi******@hotmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
hi all

I m using the visual studio designer to create 1 Dataset with 1 table
with 3 columns : Id, Name, Birthday.

Once this done, still with the designer, I m creating a datagridview
and choose my dataset as DataSource.

magic : the columns appear in the datagridview.

Still with the designer, I can change the properties of the fist column
"Id" to hide it.

now it s time to write some code :
on the cellClick event I want to get the value of the Id, unfortunaly
it throws an exception cause the column is hided

DataGridViewRow row =
(DataGridViewRow)dataGridView.Rows[e.RowIndex];

if (row != null)
{
try
{
this.selectedRowIndex =
(int)row.Cells["Id"].Value;
}
catch
{
int a = 1;
}
}

Does anyone know how to get the value of a hiding column when the user
clics on a row ?

thx for your help

ben
Nov 14 '06 #3
Hi Ben,

Well, the name of the column isn't "Id". You've named it,
"idDataGridViewTextBoxColumn".

The indexer of the row.Cells collection requires the row's Name, not the value
of the HeaderText property.

this.selectedRowIndex = (int) row.Cells["idDataGridViewTextBoxColumn"].Value;

BTW, you probably shouldn't use try..catch here. It doesn't really make sense
here; especially since you're not catching any specific exception.

--
Dave Sexton

"finleeds" <fi******@hotmail.comwrote in message
news:11**********************@h54g2000cwb.googlegr oups.com...
many thanks for your quick answer
but it s what I did :
//
// idDataGridViewTextBoxColumn
//
this.idDataGridViewTextBoxColumn.DataPropertyName = "Id";
this.idDataGridViewTextBoxColumn.HeaderText = "Id";
this.idDataGridViewTextBoxColumn.Name =
"idDataGridViewTextBoxColumn";
this.idDataGridViewTextBoxColumn.Visible = false;

and It still does not work :(

I wrote a very small project to reproduce this problem, I could send it
to you if you want ?

I ll take all advice or ideas :))

ben

Dave Sexton a écrit :
Hi Ben,

IIRC, your code should work if you really did hide the column.

By removing the column from the list in the designer you're not hiding the
column - you're completely removing it from the collection.

You must set Visible = false instead.

--
Dave Sexton

"finleeds" <fi******@hotmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
hi all

I m using the visual studio designer to create 1 Dataset with 1 table
with 3 columns : Id, Name, Birthday.

Once this done, still with the designer, I m creating a datagridview
and choose my dataset as DataSource.

magic : the columns appear in the datagridview.

Still with the designer, I can change the properties of the fist column
"Id" to hide it.

now it s time to write some code :
on the cellClick event I want to get the value of the Id, unfortunaly
it throws an exception cause the column is hided

DataGridViewRow row =
(DataGridViewRow)dataGridView.Rows[e.RowIndex];

if (row != null)
{
try
{
this.selectedRowIndex =
(int)row.Cells["Id"].Value;
}
catch
{
int a = 1;
}
}

Does anyone know how to get the value of a hiding column when the user
clics on a row ?

thx for your help

ben

Nov 14 '06 #4

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

Similar topics

4
by: Peter | last post by:
How to I changed bound column in DataGridView from DataGridViewTextBoxColumn(); to DataGridViewButtonColumn() ? Thanks Peter
5
by: bob | last post by:
Now this ought to be a simple matter. But nothing's simple in the Net world, I'm finding. In vb6 you could use "!" to force text to upper case in the format function. I've searched the vb.net...
1
by: martin1 | last post by:
Hi, All, DataGridView is populated with all coumns from database since i need some columns data for condition statement, after that I want to show rest of column in the DataGridView, so how to...
3
by: martin1 | last post by:
All, ..Net 2.0 DataGridView column sort is automatic, I don't want column sort, is anybody know how to not sort column in DataGridView? Thanks
0
by: Mike | last post by:
Hey everyone... I've got three problems with a custom DataGridView column I've built following the "How To: Host Controls in Windows Forms DataGridView Cells" article. The base editing control...
1
by: Chalkie | last post by:
Hello, I've hit what appears to be a serious problem with an unbound datagridview control that Ive added to a VB.Net program. Inadvertently I named one column 'Name' and a second 'Size'. The...
0
by: sk27ahmed | last post by:
Hi Any one can show me how to access datagridview column value on column checked unchecked. I create one column in datagridview of type checkbox,and on button click i write code to select all...
2
by: Steve | last post by:
Hi All I am using VB.net 2005 windows forms I use the Datagridview.cellformatting event to change the colours of individual cells as required and all works fine How can I do the same for...
1
by: JB | last post by:
Hi All, I'd like to display password characters in a DataGridView column, the same way I can do in a standard TextBox by using the PasswordChar property (i.e.typed characters replaced by a star...
0
by: lenniekuah | last post by:
Hi Fellow Good Guys, I need your help, Please Help me. Surprising I encounterd another problem which never happened in VB.NET but in C# technique it causing problem. Here is the explanation...
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: 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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.