Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > insert value to all cells in column
 

insert value to all cells in column

hi!

What is the code to insert a value to all cells in specified column?
MitjaGTI  Wednesday, September 24, 2008 7:22 PM

Hi MitjaGTI

That depends on when you want to do this job.

For example, if we want to do it in Button.Click, we can do it like this:

Code Snippet

private void button1_Click(object sender, EventArgs e)

{

for (int i = 0; i < this.dataGridView1.Rows.Count; i++)

{

dataGridView1.Rows[i].Cells[0].Value = "item" + i;

}

}

If there is any question, please feel free to let me know.

Thanks.

Best wishes

Jun Wang

Jun Wang Tim  Friday, September 26, 2008 9:22 AM

Then please change the Button.Click event into this:

Code Snippet

private DateTime tempDateTime;

private void button1_Click(object sender, EventArgs e)

//for (int i = 0; i < this.dataGridView1.Rows.Count; i++)

//{

// dataGridView1.Rows[i].Cells[0].Value = "item" + i;

//}

for (int i = 0; i < this.dataGridView1.Rows.Count; i++)

if (dataGridView1[0, i].Value != null)

DateTime.Parse(dataGridView1[0, i].Value.ToString());

Thanks.

Best wishes

Jun Wang

Jun Wang Tim  Friday, September 26, 2008 10:30 AM

Hi MitjaGTI

That depends on when you want to do this job.

For example, if we want to do it in Button.Click, we can do it like this:

Code Snippet

private void button1_Click(object sender, EventArgs e)

{

for (int i = 0; i < this.dataGridView1.Rows.Count; i++)

{

dataGridView1.Rows[i].Cells[0].Value = "item" + i;

}

}

If there is any question, please feel free to let me know.

Thanks.

Best wishes

Jun Wang

Jun Wang Tim  Friday, September 26, 2008 9:22 AM
hi mr. Wang

thank you!!

maybe you can help me with another "problem" Smile

let's say that my rows(i).cells(0).value = "date and time... 01.09.2008 12:00:00 format"
and i want
rows(i).cells(1).value = "rows(i).cells(0).value minus 30 minutes"

example
first cell = 14.4.2006 14:00:00; secod cell = 14.4.2006 13:30:00

any suggestions? I'm storming my brains out and i just can't get it to work
MitjaGTI  Friday, September 26, 2008 9:35 AM

Then please change the Button.Click event into this:

Code Snippet

private DateTime tempDateTime;

private void button1_Click(object sender, EventArgs e)

//for (int i = 0; i < this.dataGridView1.Rows.Count; i++)

//{

// dataGridView1.Rows[i].Cells[0].Value = "item" + i;

//}

for (int i = 0; i < this.dataGridView1.Rows.Count; i++)

if (dataGridView1[0, i].Value != null)

DateTime.Parse(dataGridView1[0, i].Value.ToString());

Thanks.

Best wishes

Jun Wang

Jun Wang Tim  Friday, September 26, 2008 10:30 AM
you are a genius, thank's 1000 times!!!

this is the code that is working for me... maybe i shuld replace the value = "" to null or smth.. :/


Code Snippet

If Me.PrevzemPosiljkDataGridView.Rows(i).Cells(0).Value.ToString = "" Then
Me.PrevzemPosiljkDataGridView.Rows(i).Cells(2).Value = Date.Now
Else
Dim casdostave = Date.Parse(PrevzemPosiljkDataGridView(0, i).Value.ToString())
Me.PrevzemPosiljkDataGridView.Rows(i).Cells(2).Value = _
casdostave.AddMinutes(-30)
End If


MitjaGTI  Friday, September 26, 2008 3:47 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridTableStyle
• Display Blobs on Reports??
• ListView control Disappearing at Mouse_Leave event
• Primary key contain was changed
• DataGridView master detail over intersect/junction table?
• How to add an image column to DataGridView control
• How to allow user to edit DataGridView column HeaderText
• Cell value disappear in DataGridView on Windows Vista
• DatagridView Combobox column displaying question
• DataGridView.CurrentCell.ErrorText doesn't show the error icon