How do I get the value of an item in a datagridview (dgv) cell?
My project has a windows form with a datagridview. The data source for the dgv is the results of a query. The columns of the dgv displays information for items to be processed. The primary key from the database row is in a hidden column. The multiselect property of the dgv is set to false. The user selects a row in the dgv and clicks a button on the form to begin processing. I need to place the primary key value into a variable to use for SQL query parameters in other automations.
I tried using the dgv current row cells get item method, but the method returns a DataGridViewCell object.
***Edited by Moderator Marissa to update Platform Capability tags****
I resolved my problem by extracting a proxy for the DataGridViewCell. The proxy exposes the properties for the cell object. However, now I get a runtime error that the link from the cell value property link to the integer variable cannot be created. There is not a variant type variable listed in the toolbox. There also are not any converters listed in the toolbox. I presume the error is because there is not an implicit conversion defined to convert the cell value object to int.
Posted: 2 months ago
Updated: 2 months ago
Posted: 29 Jun 2021 12:56 EDT Updated: 29 Jun 2021 13:12 EDT
@ThomasSasnett Thank you! I was able to accomplish the task in a slightly different manner. I created a script to get the cell value using the current row object from the datagridview. When the button is clicked, I check the selected rows collection count property is greater than zero. The multiselect property is currently set to false, but that could change in the future. I selected the current row property from the datagridview and pass the DataGridViewRow object as the script parameter. The script simply uses the Convert.ToInt32(Object) overload to return the cell's value as a 32-bit integer. I attached an image of the automation section where I get the cell value.