i want to delete row from datagrid view when all row column get 0

sagar shedge
sagar shedge used Ask the Experts™
on
i have 6   to 7 column in datagrid view in that 1st column name is "name" 2nd to 7th all have some  numeric values i want to delete row when that numeric values get 0 in windows form C#
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

Commented:
Do you think what to do the manipulation from your Data Source instead of DataGridView?

Author

Commented:
no it must be get disable or delete from data grid view only
Ryan ChongSoftware Team Lead

Commented:
"delete" means it was generated, and then somehow it was "removed". it's the same in some sense that we exclude it before it's being generated. That's my idea.
IT Professional
Top Expert 2015
Commented:
2nd to 7th all have some  numeric values i want to delete row when that numeric values get 0 in windows form C#

When all column has 0 value?
If Yes, then please find below code (not tested)
//Delete ROW if all columns empty
void DataGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
	if(e.Row.RowType == DataControlRowType.DataRow)
	{
		var isZero = true;
		//Loop Starts from 1 as First column (Name) needs to be omit
		for(int i=1;e.Row.Cells.Count;i++)
		{
			if(!String.IsNullOrEmpty(e.Row.Cells[i].Text)
				isZero = false;
		}

		//Delete ROW - If all rest of all columns empty
		if(isZero)
		{
			  DataGridView.DeleteRow(e.Row.RowIndex) 
		}
	}
}

Open in new window

OR When any column has 0 value?
If Yes, then please find below code change in above function(not tested)
//Change below logic in above code to 
//Delete ROW if any columns (except first) empty
var isZero = false;
//Loop Starts from 1 as First column (Name) needs to be omit
for(int i=1;e.Row.Cells.Count;i++)
{
	if(String.IsNullOrEmpty(e.Row.Cells[i].Text)
	{	
		isZero = true; break;
	}
}

Open in new window

NOTE: I have made condition for to check cell value is empty or not, you can change it to check for "0"
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Prakash Samariya (https:#a42062950)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial