Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have datagridview in which i want 3 column. i want in first coulmn have label control and other two column is textbox.below is sample


description monthly Yearly

pf(label) 100(txtbox) 1200(txtbox)



i dont want to use database . in datagridview display five rows and user enter amt in monthly column it will automatically calculate year column. pls help me i m new in programming.
Posted
Comments
Kenneth Haugland 2-Aug-12 12:05pm    
This would be so simple in WPF that it would make you cry.... :)
[no name] 2-Aug-12 12:16pm    
Okay so you told us what you want but you have told us what problem you are having or posted any code that demonstrates any sort of an problem.

To me it seems like you don't really need to add Labels or TextBoxes to your grid to do this.

Add your 5 rows
C#
dataGrid.RowCount = 5;


Set your first (and probably third) columns to ReadOnly
C#
dataGrid.Columns[0].ReadOnly = true;


Then add and event handler to calculate your year based on input in the second column. Here's a link that should help:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellendedit.aspx[^]
 
Share this answer
 
In text box changed event of monthly column, you can write code to calculate yearly column value as:

C#
Private void datagridview_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
   e.Control.TextChanged +=new EventHandler(txtMonthly_TextChanged);
   cntObject=e.Control;
   cntObject.TextChanged +=txtMonthly_TextChanged;
}

Private void txtMonthly_TextChanged(object sender, EventArgs e)
{
  if(cntObject.Text!=string.Empty)
  {
     txtYearly.Text=int.Parse(cntObject.Text)*12;
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900