change cell in datagridview to empty value

John

I have method to change cell in datagridView and works fine when i rewrite text (String) .
But I want for example rewrite email to empty value and I dont know how do this.
I can only rewrite email to another email (string to another string)

My method to change cell is :

public void ChangeCellEmail(int col, string[] emails)
    {


        string sep = ";";
        string text = "";

        foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
        {


            for (int i = 0; i < emails.Length ;i++)
            {

                if (emails[i].ToString().Trim() != "")
                {


                    text = text + emails[i] + sep ;
                    dataGridView1.Rows[cell.RowIndex].Cells[col].Value = text;
                }
            }

        }

    }

The calling code of my method is

            string mail = txtBox1.Text;
            string mail1 = txtBox2.Text;
            string mail2 = txtBox3.Text;
            string mail3 = txtBox4.Text;
            string mail4 = txtBox5.Text;

            string[] mails = new string[] { mail, mail1, mail2, mail3, mail4 };


            frm1.ChangeCellEmail(2, mails);
            this.Dispose();

Thanks for help guys .

Hexie

Using the following code I can pass in 5 complete email address's of which some / all could be "empty" and the tempVar will always contain the correct data.

public Form1()
    {
        InitializeComponent();

        const string mail = "First";
        const string mail1 = "Second";
        const string mail2 = "Third";
        const string mail3 = "";
        const string mail4 = "Fifth";

        var mails = new string[] { mail, mail1, mail2, mail3, mail4 };

        ChangeCellEmail(2, mails);
    }


    public void ChangeCellEmail(int col, string[] emails)
    {
        var sep = ";";
        var text = "";
        var tempVar = ""; //New temp variable (representing your dataGrid.value)

        for (int emailList = 1; emailList < 5; emailList++)
        {
            for (var i = 0; i < emails.Length; i++)
            {

                if (emails[i].Trim() != "")
                {
                    text = text + emails[i] + sep;
                    tempVar = text;
                }
                else
                {
                    tempVar = string.Empty;
                }
            }

        }

    }

Check the tempVar on each loop and you'll see what I am referring to.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Datagridview Change cell color of non empty cell

From Dev

Change DataGridView Cell Value Programmatically

From Dev

Pass empty cell value from datagridview

From Dev

Change datagridview cell value in edit mode

From Dev

How to change value of one cell onchange of other cell value in DataGridview

From Dev

Change datagridview cell to combobox if empty/(null) c#

From Dev

Change of the edited cell in a datagridview cell

From Dev

C# DataGridView: How to change a single cell value

From Dev

How to add a row and change cell value in DataGridView from a different thread?

From Dev

DataGridView Cell Value Changing

From Dev

DataGridView Cell Value Changing

From Dev

Hiding a value in a datagridview cell

From Dev

how to change cell values in datagridview according to a cell

From Dev

Convert a DataGridView Cell Value into a DateTime

From Dev

How to change value of datagridview?

From Dev

Empty value in Excel cell?

From Dev

How can i change color of particular row in datagridview, where a cell value is first timestamp of each day?

From Dev

For a Windows Forms Application using `DataGridView`, how can I check a value in my DataSource and change the color of a separate cell?

From Dev

datagridview cell mouse hover backcolor change

From Dev

change color of cell of dynamicly created datagridview

From Dev

Change selected Treeview Node on Datagridview Cell Click

From Dev

Change datagridview cell background based on a external parameter

From Dev

How to change text of the top left cell of a datagridview?

From Dev

Change text of a cell on dataGridView_CellFormatting

From Dev

Datagridview checkbox cell change color of button and drawline

From Dev

Datagridview won't change cell color

From Dev

Change Cell Value if There is Overflow

From Dev

Cell value change with Month

From Dev

Change value of cell in Javascript

Related Related

  1. 1

    Datagridview Change cell color of non empty cell

  2. 2

    Change DataGridView Cell Value Programmatically

  3. 3

    Pass empty cell value from datagridview

  4. 4

    Change datagridview cell value in edit mode

  5. 5

    How to change value of one cell onchange of other cell value in DataGridview

  6. 6

    Change datagridview cell to combobox if empty/(null) c#

  7. 7

    Change of the edited cell in a datagridview cell

  8. 8

    C# DataGridView: How to change a single cell value

  9. 9

    How to add a row and change cell value in DataGridView from a different thread?

  10. 10

    DataGridView Cell Value Changing

  11. 11

    DataGridView Cell Value Changing

  12. 12

    Hiding a value in a datagridview cell

  13. 13

    how to change cell values in datagridview according to a cell

  14. 14

    Convert a DataGridView Cell Value into a DateTime

  15. 15

    How to change value of datagridview?

  16. 16

    Empty value in Excel cell?

  17. 17

    How can i change color of particular row in datagridview, where a cell value is first timestamp of each day?

  18. 18

    For a Windows Forms Application using `DataGridView`, how can I check a value in my DataSource and change the color of a separate cell?

  19. 19

    datagridview cell mouse hover backcolor change

  20. 20

    change color of cell of dynamicly created datagridview

  21. 21

    Change selected Treeview Node on Datagridview Cell Click

  22. 22

    Change datagridview cell background based on a external parameter

  23. 23

    How to change text of the top left cell of a datagridview?

  24. 24

    Change text of a cell on dataGridView_CellFormatting

  25. 25

    Datagridview checkbox cell change color of button and drawline

  26. 26

    Datagridview won't change cell color

  27. 27

    Change Cell Value if There is Overflow

  28. 28

    Cell value change with Month

  29. 29

    Change value of cell in Javascript

HotTag

Archive