Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > set value to GridView row
 

set value to GridView row

I want to store a value for every row in a gridview.
I try to set these:
myGridview.Rows[a rowindex].HeaderCell.Value = the value what i want to set;
or
myGridview.Rows[a rowindex].Tag = the value what i want to set;

but after a cell click these properties store null value

How can i set a value for the gridviewrow?
  • Edited byRobertHun Saturday, July 11, 2009 5:28 PMjust
  • Edited byRobertHun Saturday, July 11, 2009 5:26 PM
  • Edited byRobertHun Saturday, July 11, 2009 5:27 PMjust
  • Edited byRobertHun Saturday, July 11, 2009 5:26 PMjust
  •  
RobertHun  Saturday, July 11, 2009 5:25 PM
Thank you for your help.

I deleted this solution from my code.
I resolve my proble.
I add a new unvisible column to my datagridview and i set the value in the cells of column.

Thank you again.

Regards.
RobertHun  Thursday, July 16, 2009 2:54 PM
I just tried setting the Tag property of the row and then displaying it to the Debug window at a later point and it worked fine for me.

How/where are you setting the tag?

How/where are you retrieving the tag?
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Monday, July 13, 2009 6:59 PM
I have a Form with the DataGridView. In this Form.cs in a method i set the Tag property. I call the this method in the Form_Load. When i run the App in Debug mode, i watch the value of the Tag. After the Form load the value is ok. But when i click on the DataGridView cell the value change null.
I put a break point at the begining of the myDataGridView_CellClick method and there the value is null by that time.

I set and retrieve like these:

in the setter method:


myGridview.Rows[a rowindex].Tag = the value what i want to set;

int the myDataGridView_CellClick method:


var x = myGridview.Rows[a rowindex].Tag;
  • Edited byRobertHun Tuesday, July 14, 2009 10:32 AMjust
  •  
RobertHun  Tuesday, July 14, 2009 10:28 AM

Do you have any other code that is either clearing the rows or creating a new myGridView?

Are you rebinding after setting the tag? I would think that rebinding would cause you to loose any values associated with the rows.

Hope this helps.


www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Tuesday, July 14, 2009 6:44 PM
Thank you for your help.

I deleted this solution from my code.
I resolve my proble.
I add a new unvisible column to my datagridview and i set the value in the cells of column.

Thank you again.

Regards.
RobertHun  Thursday, July 16, 2009 2:54 PM

You can use google to search for other answers

Custom Search

More Threads

• Problem in DataGridView
• DataGridView duplicated columns issue - what's the fix/workaround?
• Combining checkbox and comobox behavior in datagridview
• Get trouble when binding data to combobox
• return type
• CheckedListBox and DataMember/ValueMember
• Best way to handle handle database schema change for generated dataset
• [C#]Datagridview copy/paste from a row to another row
• Missing Wizards,Builder,Library in MS Access 2003
• How to display an XML file in a DataGridView