Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
if (dataGridView1.CurrentRow.Cells[0].Value.ToString() == "a")
              {
                  (dataGridView1.CurrentRow.Cells[1] as DataGridViewComboBoxCell).Items.Add("a1"); // populate combobox with items
                  //dataGridView1.CurrentRow.Cells[2].Value.ToString() == "Hallo"; // Here I try to set the text in  cell 3 to Hallo

              }


What to do to set dgv cell[2] ="Hallo" ?

Tryed this
C#
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
  {
      if (dataGridView1.CurrentCell.Value !=null)
      if (dataGridView1.CurrentCell.Value.ToString()=="a")
      {

          (dataGridView1.CurrentRow.Cells[1] as DataGridViewComboBoxCell).Items.Clear();
          (dataGridView1.CurrentRow.Cells[1] as DataGridViewComboBoxCell).Items.Add("a1");
          dataGridView1.Rows[0].Cells[2].Value = "Hallo";

      }


Then i got System.ArgumentException:Value on DataGridViewComboBoxCell is not valid
Posted
Updated 5-Nov-13 3:18am
v2
Comments
ZurdoDev 5-Nov-13 7:42am    
Did you try dataGridView1.CurrentRow.Cells[2].Value="Hallo"?

Try changing this

dataGridView1.CurrentRow.Cells[2].Value.ToString() == "Hallo"; 
// Here I try to set the text in  cell 3 to Hallo


to

C#
datagridview1.CurrentRow.Cells[2].Value = "Hello";
 
Share this answer
 
try this
datagridview1.Rows[currentrowindex].Cells[2].Text="hello"


if it is in windows try it as
datagridview1.Rows[currentrowindex].Cells[2].value="hello"
 
Share this answer
 
v2
Comments
Member 10321326 5-Nov-13 8:54am    
Error 1 'System.Windows.Forms.DataGridViewCell' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'System.Windows.Forms.DataGridViewCell' could be found (are you missing a using directive or an assembly reference?)

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