.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

about Datagrid in c#.net window application

Posted By: Vikramraj     Posted Date: December 10, 2010    Points:2   Category :C#
how to get selected row and cell value from datagrid in c#.net window application

Responses
Author: krishana singh             
Posted Date: December 10, 2010     Points: 5   

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int a = dataGridView1.CurrentRow.Index;

b = Convert.ToInt16(dataGridView1.Rows[a].Cells[5].Value);
cmbcategory.Text = dataGridView1.Rows[a].Cells[1].Value.ToString();
txtitemname.Text = dataGridView1.Rows[a].Cells[0].Value.ToString();
txtitemquantity.Text = dataGridView1.Rows[a].Cells[2].Value.ToString();
txtitemrate.Text = dataGridView1.Rows[a].Cells[3].Value.ToString();
cmbdate.Text = dataGridView1.Rows[a].Cells[4].Value.ToString();
txtstockno.Text = dataGridView1.Rows[a].Cells[5].Value.ToString();
}

Author: Syed Shakeer Hussain             
Posted Date: December 10, 2010     Points: 5   

Hi

Before using this code you have to double click your DataGridview and write the  code 

Private void dataGridView1_CellContentClick_(objectsender,DataGridViewCellEventArgs e)
{

i = dataGridView1.SelectedCells[0].RowIndex;
textBox1.Text = dataGridView1.Rows[i].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
textBox3.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
}


For more information check the below link

http://www.dotnetspark.com/kb/608-how-to-get-values-slected-cell-row-datagridviewwindows.aspx




Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend