Click here to Skip to main content
15,911,142 members
Please Sign up or sign in to vote.
1.75/5 (5 votes)
See more:
i want to delete file in datagridview.i taking datatable in datagridview so i want to delete file from datatable and these file can be stored in folder not database .so i want to code for entity framework.so plz give me good ans.
Posted
Updated 21-Nov-13 22:28pm
v2
Comments
OriginalGriff 13-Nov-13 3:06am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
A DataGridView does not normally contain files, so you need to be clearer about what you hold in the DGV, where you get it from, and how you need to access it.
Use the "Improve question" widget to edit your question and provide better information.
Member 10279329 25-Nov-13 0:38am    
sir,
my file is delete from datagridview row but .next time i am scan file then display deleted file in gridview .these file cannot delete from folder.so i am tired too.so plz help me add better information.
thanks,
Nooa 25-Nov-13 19:21pm    
stop downvoting idiot!
ask a real question first!

i still dont know what you want to do?!

are you reading a directory and adding all files to a dgv?
after that you deleting one file from the dgv but you execute the "scan-function" again and its there again?
sure... as long you dont delete it from file, or mark it as "do not read" it will be in the dgv all the time!

so what is your problem!?
and again! stop downvoting executeable code which is a working response to your "question"!
Er Daljeet Singh 22-Nov-13 4:32am    
for a good answer post your question carefully..

sir,
sory ,but my file is delete from datagridview but not folder so how can i do .so plz help me your instruction very usefull to me.
thanks
 
Share this answer
 
here a solution which should answer your question.
Important to prevent errors:
- setup the dgv selection mode to "selectFullRow"
- execute the FillGrid on program start
- add button to form with execute the BtnDeleteFileFromDgv on Click

C#
private void FillGrid()
{
	dataGridView1.Rows.Clear();

	if (!dataGridView1.Columns.Contains("fileName"))
		dataGridView1.Columns.Add("fileName", "File names");

	foreach (var file in Directory.GetFiles(@"c:\MyDir\"))
	{
		var index = dataGridView1.Rows.Add();
		dataGridView1.Rows[index].Cells["fileName"].Value = file;
	}
}
private void BtnDeleteFileFromDgv_Click(object sender, EventArgs e)
{
	if(dataGridView1.SelectedRows.Count == 0)
		return;

	var fileName = dataGridView1.SelectedRows[0].Cells["fileName"].Value.ToString();
	File.Delete(fileName);
	FillGrid();
}


if it is working, please dont forget to rate the post
 
Share this answer
 

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