Hi im new to c#.. just wondering how to convert this vba code:-
x = 1
For i = 2 To 100
x = x + i
ActiveCell.Value = x
Here is how I got it to work (learning for myself) ... but I went with a WHILE loop to make it more flexible. And I defined the values separately so they could be defined on the fly, or the code could be integrated into a method that received starting and max values.
Prep ... I dropped a DataGridView on the form and created and gave it one column. I did not define any rows.
Then I created a button, and dropped this code into the Click event:
private void button1_Click(object sender, EventArgs e)
// Starting value
// Maximum value
Int32 z = 100;
// Current Cell index
Int32 cell = 0;
// Make sure we can write to the cells...
dataGridView1.ReadOnly = false;
while(x <= z)
dataGridView1[0,cell].Value = x.ToString();
// Set the active cell to the first one...
dataGridView1.CurrentCell = dataGridView1[0,0];
Please mark this as solved if it answered your question. :)