C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » DataGridView »

selected row content of a datagridview


Posted Date: 11 Jun 2009    Resource Type: Code Snippets    Category: DataGridView
Author: Viji RAJKUMARMember Level: Diamond    
Rating: 1 out of 5Points: 10 (Rs 5)



c# Code

To select the particular column's value whenever the row selection is changing in the datagridview


Add the handler to OnLoad function of the form

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

//Add Selection changed handler
dbGridView.SelectionChanged += new EventHandler(dbGridView_SelectionChanged);

}


//Whenever the row selection is changed, the text box is filled with the Column 1 data

private void dbGridView_SelectionChanged (object sender, EventArgs e)
{

DataGridView dgv = (DataGridView)sender; //User selected WHOLE ROW (by clicking in the margin)

if (dgv.SelectedRows.Count > 0)
textBox1.Text = (dgv.SelectedRows[0].Cells[0].Value.ToString());

//User selected a cell (show the first cell in the row)
if (dgv.SelectedCells.Count > 0)
textBox1.Text = (dgv.Rows[dgv.SelectedCells[0].RowIndex].Cells[0].Value.ToString());

//User selected a cell, show that cell
if (dgv.SelectedCells.Count > 0)
textBox1.Text =(dgv.SelectedCells[0].Value.ToString());
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Selected row content of a datagridview  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: DataGridView with Row Numbers
Previous Resource: Populate DataGridView From Excel Sheet
Return to Discussion Resource Index
Post New Resource
Category: DataGridView


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use