?
Solved

Winforms Datagrid.  How to retrieve single cell value after double click

Posted on 2006-06-05
8
Medium Priority
?
584 Views
Last Modified: 2008-01-09
I have a datagrid bound to a dataset that can be created in several ways based on user input.  Once it is displayed (it is readonly), I want the user to double click to select a row, and then retreive values from 2 cells to use as key to retrieve the data from the database.  How do I get the values of the cells?  And can the cells be hidden?
0
Comment
Question by:MGothelf
  • 3
  • 3
  • 2
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16836596
1) .NET version?

2) Cells can't be hidden, but columns can.

3) Individual cell values:

   string cellValue = dataGrid1.Item[column, row].ToString();

Bob
0
 

Author Comment

by:MGothelf
ID: 16836966
I know how to tell the column that is clicked (dataGrid1.CurrentCell.ColumnIndex), but how do I know which row???
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16837079
1) .NET version?  2005?

2) DataGridView?

3) With 2003 and the DataGrid, the current column is dataGrid1.CurrentCell.ColumnNumber and row is dataGrid1.CurrentCell.RowNumber.

4) I am thinking now that you are using a DataGridView with 2005.

5) With 2005 and the DataGrid, the current column is dataGrid1.CurrentCell.ColumnIndex and row is dataGrid1.CurrentCell.RowIndex.

Bob
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:MGothelf
ID: 16837188
Yes I am using a DataGridView with 2005.

So I can get the row and column, but DataGridView does not have a definition for Item.  What is the equivalent of dataGrid1.Item[column, row].ToString();

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16837542
Try it anyway, even if Intellisense doesn't show it.

Also try this:

 string cellValue = dataGrid1[column, row].Value;

or this:

  DataGridViewCell cell = dataGrid1[columnIndex, rowIndex];
  string cellValue = cell.Value;

Bob
0
 
LVL 6

Accepted Solution

by:
MuhammadAdil earned 2000 total points
ID: 16839946
Hello Dear

i think u want to get column values from selected row
so u can get values in that way

string column1 = this.GrdLibrayDB.CurrentRow.Cells["ColumnName"].Value; \\ColumnName= (Such As Customer ID)
string column2 = this.GrdLibrayDB.CurrentRow.Cells["ColumnName"].Value;

Hidding Specific Column

this.ColumnName.Visible = false;
0
 
LVL 6

Expert Comment

by:MuhammadAdil
ID: 16840013
Hello Dear

GrdLibraryDB is my gridname u should change this according to ur grid
0
 

Author Comment

by:MGothelf
ID: 16851737
Thanks, your solution works fine, although it should read:

string column1 = this.GrdLibrayDB.CurrentRow.Cells["ColumnName"].Value.ToString();

MG
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question