473,698 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get the value from datagridview to textbox in c#

8 New Member
how to get the value from datagridview to textbox on c#?
im a beginner in c#.. and im having a hard time searching for the error free code for this.. need help!!!!
Nov 22 '11
13 43976
arie
64 New Member
in CellContentClic k you have to ensure that the index you're trying to process:
- is non-negative, meaning isn't -1 (index of headers)
- less than the size of collection, meaning that it isn't the index of new row or index isn't greater than the number of rows or columns you actually have
Nov 29 '11 #11
adriancs
122 New Member
or, you can try dataGridView1.C ellClick

Expand|Select|Wrap|Line Numbers
  1. public partial class Form1 : Form
  2. {
  3.     public Form1()
  4.     {
  5.         InitializeComponent();
  6.         this.dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
  7.     }
  8.  
  9.     void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
  10.     {
  11.         if (e.RowIndex < 0 || e.ColumnIndex < 0)
  12.             return;
  13.  
  14.         string id, name, price, desc, quan;
  15.         id = dataGridView1.Rows[e.RowIndex].Cells[0].Value + "";
  16.         name = dataGridView1.Rows[e.RowIndex].Cells[1].Value + "";
  17.         price = dataGridView1.Rows[e.RowIndex].Cells[2].Value + "";
  18.         desc = dataGridView1.Rows[e.RowIndex].Cells[3].Value + "";
  19.         quan = dataGridView1.Rows[e.RowIndex].Cells[4].Value + "";
  20.         txtID.Text = id;
  21.         txtName.Text = name;
  22.         txtPrice.Text = price;
  23.         txtDesc.Text = desc;
  24.         txtQuan.Text = quan; 
  25.     }
  26. }
Nov 30 '11 #12
marz javier
8 New Member
arie, its solved!! thank you so much..
Dec 1 '11 #13
yagoob
1 New Member
How are you
How Collect column from data grid view in text box
Dec 29 '12 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2292
by: velu | last post by:
Problem in getting value from textbox & radiobuttonlist to a valuable inside a datagid. I want to insert a record into a table thru datagrid. Here is the code (see below) Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles DataGrid1.ItemCommand
1
5095
by: rudranee | last post by:
Hi everyone, I want to know how can i edit a value in textbox in html . I have a field where I have already put a value from database but i also want to edit it . for example ,if in a textbox i put a value 'abc' set in the value attribute <inptu type=text value="<%= var1%>"> .now I want to change the value in the textbox and add it to database. hoe should I do it.
0
2488
by: sunny076 | last post by:
Hi, I am having difficulties creating a derived class for DisabledDataGridViewTextBoxColumn and cell when the VisualStyle is not supported. Basically I am down to either using ControlPaint or Graphics to achieve this. But with Graphics, I am not sure how I can make them diabled. Below are my codes:
5
13511
by: SKS | last post by:
hi all i would like to know how to restrict user from entering numeric value ina textbox..using C# if user try to enter text it shouldnt be allowed.. i tried errror provider.. but it doesnt met my requirement.. thanks in advance for ur valuable reply let me know the best to do it urs
6
3142
by: Chris | last post by:
I created a very simple web page in asp.net. there are only a textbox and a button on the page. when the page loads into web browser there is current date in the textbox. but the date can be changed by user as well. now, when you press the button the date should be inserted into a database. the problem is that , yes it has been inserted, but it is always the current date. even if a user modified the date, it would be inserted the current...
1
1881
by: abirami elango | last post by:
Hi, i have created a web application in vb.net. i have assigned a value to the textbox during page UNLOAD event as below.. ......... Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload txtPopConfirm.Text = intCountAnswer1 End Sub
1
2325
by: adepvivek | last post by:
Hi everybody, I am using textbox in gridview as template. And I want to stored the value of textbox. For that I want to pass the textbox value to stored procedure. So please give me solution.
5
10140
oranoos3000
by: oranoos3000 | last post by:
hi I want to send value of textbox without using form tag and submit button to another page? Is it possible with php ? How do I get this thing work? thanks alot
2
5106
by: s k parimal | last post by:
How to validate decimal value in textbox using C#? I am using this (^(*|\d*\d{1}?\d*)$) but it not working help
0
8608
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7732
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.