strProdNum = dataGridView.Columns[0].ToString();
4 Replies - 4614 Views - Last Post: 23 November 2010 - 01:11 PM
#1
Datagridview to return values in column (to string?)
Posted 18 November 2010 - 02:10 PM
I am working with a Windows form that includes a datagridview - where the user enters their information. Everything works fine with inserting into the database, however, I need to change the datagridview before it enters the database. The user enters a value (ProductNumber) in a specific column of the database, however, I need to convert the ProductNumber into the ID (in a separate column) before it enters the database. (I understand the SELECT part, I tested it with a textbox and it worked fine) - but am confused how to get the ProductNumber, since it is in a datagridview and cannot easily be transferred into a string. (My datagridview also allows multiple entries) - The ID is the primary key from a database table, which needs to be the number entered into my database table. I apologize if I am not being too clear, it is kind of confusing. Is there an easier way to do this? Thanks for any help/suggestions.
Replies To: Datagridview to return values in column (to string?)
#2
Re: Datagridview to return values in column (to string?)
Posted 18 November 2010 - 02:37 PM
Something like this:
//Assuming Cell 0 is the productNumber. Also assuming you want to get //the productNumber on the click event. You can use a number instead of 'e'. productNumber = dataGridView1.Rows[e.RowIndex].Cells[0].Value);
#3
Re: Datagridview to return values in column (to string?)
Posted 18 November 2010 - 02:51 PM
Sergio Tapia, on 18 November 2010 - 01:37 PM, said:
Something like this:
//Assuming Cell 0 is the productNumber. Also assuming you want to get //the productNumber on the click event. You can use a number instead of 'e'. productNumber = dataGridView1.Rows[e.RowIndex].Cells[0].Value);
Thanks so much for your reply - I am playing around with it, but even when I change to a number instead of 'e' I keep getting the error message "'int' does not contain a definition for 'RowIndex' and no extension method 'RowIndex' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)
Probably something really simple - but my brain is at it's limit
#4
Re: Datagridview to return values in column (to string?)
Posted 18 November 2010 - 02:52 PM
Please post your code and say what line the error is firing.
#5
Re: Datagridview to return values in column (to string?)
Posted 23 November 2010 - 01:11 PM
mjw85, on 18 November 2010 - 01:10 PM, said:
I am working with a Windows form that includes a datagridview - where the user enters their information. Everything works fine with inserting into the database, however, I need to change the datagridview before it enters the database. The user enters a value (ProductNumber) in a specific column of the database, however, I need to convert the ProductNumber into the ID (in a separate column) before it enters the database. (I understand the SELECT part, I tested it with a textbox and it worked fine) - but am confused how to get the ProductNumber, since it is in a datagridview and cannot easily be transferred into a string. (My datagridview also allows multiple entries) - The ID is the primary key from a database table, which needs to be the number entered into my database table. I apologize if I am not being too clear, it is kind of confusing. Is there an easier way to do this? Thanks for any help/suggestions.
strProdNum = dataGridView.Columns[0].ToString();
I figured this issue out - thought I would post the solution (worked for me - hopefully will be helpful to someone else!
strProdNum = dataGridView.Rows[e.RowIndex].Cells["PRODUCTNUM"].EditedFormattedValue.ToString();
(["PRODUCTNUM"] was the name of my column)
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|