.Net RRS feed

  • Question

  • my question is how clear dropdown and textbox values in grid view

    Monday, July 24, 2017 12:41 PM

All replies

  • Hi kannankrishnan,

    >>my question is how clear dropdown and textbox values in grid view

    I'm not sure what is your gridview here, is it a GridView within WebForm or a DataGridView within Windows Forms?

    If it is a datagridview within Winform, how do you fill the data in the datagridview?

    If there is a column typed DataGridViewTextBoxColumn or DataGridViewComboBoxColumn, then you can get the column index, then use the following code to clear it:

    private void button1_Click(object sender, EventArgs e)
        int rows = dataGridView1.RowCount - 1;
        for (int i = 0; i < rows; i++)
            //Suppose the second column is the column to be cleared
            dataGridView1.Rows[i].Cells[1].Value = "";

    Or there are only a little cells is filled with ComboBox or textbox that you want to clear, then you can get the cell then clear it directly:

    //dataGridView1.Rows[i].Cells[j] is the cell that you want to clear
    dataGridView1.Rows[i].Cells[j].Value = "";

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Monday, July 31, 2017 8:32 AM
    Tuesday, July 25, 2017 6:16 AM