clear datagridview duplicate rows and keep unique rows












2















so when filling my datagridview I normally do something like



    public void FillTable(CoBRAMetaField metaFields)
{
dataGridView.Rows.Clear();

// do something with metaFields
}


Important:




  • CoBRAMetaField is a object with a ID and other stuff


  • Each row in the grid holds a metafield object



My grid gets filled correctly (sorry, the language is german)



enter image description here



When I fill the grid another time I only want to remove the rows with metaFields that don't exist in the new metaFields array. I want this behaviour because when a user selected a value for this row I don't want it to get removed and created again because then the selected value is removed too.



I came up with this



    public void FillTable(CoBRAMetaField metaFields)
{
for (int i = 0; i < dataGridView.Rows.Count; i++) // loop through the grid rows
{
double metaFieldID = (dataGridView.Rows[i].Cells[0].Tag as CoBRAMetaField).ID; // get the ID from the row metaField

if (metaFields.Any(field => field.ID == metaFieldID)) // Does it exist?
metaFields = metaFields.Where(field => field.ID != metaFieldID).ToArray(); // Remove it from the new array
else // it doesn't exist
dataGridView.Rows.Remove(dataGridView.Rows[i]); // remove the row
}

// Fill the grid with the remaining metaFields
}


The first run gets initialized correctly



enter image description here



the second run seems to crash, some fields remain empty



enter image description here



when I press the button on this row I get a nullpointer exception. I only get this error when using the "new code" so am I missing something? Is there something I didn't think about?





I will provide a full example here



At first create a DataGridView and Button on the form. Create a file for all required classes and take this snippet



https://pastebin.com/BFmr2ps9



After that fill the forms code with some test data



https://pastebin.com/Yz84Akkj



and now setup the DataGridView logic



https://pastebin.com/qH6kZKZv



I added



dataGridView.AllowDrop = false;
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToOrderColumns = false;
dataGridView.AllowUserToResizeRows = false;


if you just want to copy paste but you can also do it by the forms designer. Have a look at dataGridView.Rows.Clear(); this provides a working example. Comment it out and use the code above to test the incorrect example










share|improve this question

























  • Link you gave is empty.

    – Aleksa Ristic
    Nov 21 '18 at 12:25











  • okay this is weird, I updated it

    – MHComputech
    Nov 21 '18 at 12:39











  • There is a lot missing from the posted/linked code. There are no definitions for the following variables… CoBRAMetaField, ReleaseSetUpData and FieldName… Without these definitions, finding help may be scarce. In addition, there is a link to some code that does not appear to be used anywhere. Where is the MetaFieldTable class used? Your comment… ”I will provide a full example here but I don't think it's needed” … I think it is needed.

    – JohnG
    Nov 23 '18 at 0:50











  • @JohnG I'm sorry. Now you can take a full working example if someone wants to try to reproduce the project.

    – MHComputech
    Nov 23 '18 at 8:27











  • When I fill the grid another time I only want to remove the rows with metaFields that don't exist in the new metaFields array. - So why you not simply clear the rows and add all rows from the new array?

    – Fabio
    Nov 23 '18 at 8:39
















2















so when filling my datagridview I normally do something like



    public void FillTable(CoBRAMetaField metaFields)
{
dataGridView.Rows.Clear();

// do something with metaFields
}


Important:




  • CoBRAMetaField is a object with a ID and other stuff


  • Each row in the grid holds a metafield object



My grid gets filled correctly (sorry, the language is german)



enter image description here



When I fill the grid another time I only want to remove the rows with metaFields that don't exist in the new metaFields array. I want this behaviour because when a user selected a value for this row I don't want it to get removed and created again because then the selected value is removed too.



I came up with this



    public void FillTable(CoBRAMetaField metaFields)
{
for (int i = 0; i < dataGridView.Rows.Count; i++) // loop through the grid rows
{
double metaFieldID = (dataGridView.Rows[i].Cells[0].Tag as CoBRAMetaField).ID; // get the ID from the row metaField

if (metaFields.Any(field => field.ID == metaFieldID)) // Does it exist?
metaFields = metaFields.Where(field => field.ID != metaFieldID).ToArray(); // Remove it from the new array
else // it doesn't exist
dataGridView.Rows.Remove(dataGridView.Rows[i]); // remove the row
}

// Fill the grid with the remaining metaFields
}


The first run gets initialized correctly



enter image description here



the second run seems to crash, some fields remain empty



enter image description here



when I press the button on this row I get a nullpointer exception. I only get this error when using the "new code" so am I missing something? Is there something I didn't think about?





I will provide a full example here



At first create a DataGridView and Button on the form. Create a file for all required classes and take this snippet



https://pastebin.com/BFmr2ps9



After that fill the forms code with some test data



https://pastebin.com/Yz84Akkj



and now setup the DataGridView logic



https://pastebin.com/qH6kZKZv



I added



dataGridView.AllowDrop = false;
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToOrderColumns = false;
dataGridView.AllowUserToResizeRows = false;


if you just want to copy paste but you can also do it by the forms designer. Have a look at dataGridView.Rows.Clear(); this provides a working example. Comment it out and use the code above to test the incorrect example










share|improve this question

























  • Link you gave is empty.

    – Aleksa Ristic
    Nov 21 '18 at 12:25











  • okay this is weird, I updated it

    – MHComputech
    Nov 21 '18 at 12:39











  • There is a lot missing from the posted/linked code. There are no definitions for the following variables… CoBRAMetaField, ReleaseSetUpData and FieldName… Without these definitions, finding help may be scarce. In addition, there is a link to some code that does not appear to be used anywhere. Where is the MetaFieldTable class used? Your comment… ”I will provide a full example here but I don't think it's needed” … I think it is needed.

    – JohnG
    Nov 23 '18 at 0:50











  • @JohnG I'm sorry. Now you can take a full working example if someone wants to try to reproduce the project.

    – MHComputech
    Nov 23 '18 at 8:27











  • When I fill the grid another time I only want to remove the rows with metaFields that don't exist in the new metaFields array. - So why you not simply clear the rows and add all rows from the new array?

    – Fabio
    Nov 23 '18 at 8:39














2












2








2


0






so when filling my datagridview I normally do something like



    public void FillTable(CoBRAMetaField metaFields)
{
dataGridView.Rows.Clear();

// do something with metaFields
}


Important:




  • CoBRAMetaField is a object with a ID and other stuff


  • Each row in the grid holds a metafield object



My grid gets filled correctly (sorry, the language is german)



enter image description here



When I fill the grid another time I only want to remove the rows with metaFields that don't exist in the new metaFields array. I want this behaviour because when a user selected a value for this row I don't want it to get removed and created again because then the selected value is removed too.



I came up with this



    public void FillTable(CoBRAMetaField metaFields)
{
for (int i = 0; i < dataGridView.Rows.Count; i++) // loop through the grid rows
{
double metaFieldID = (dataGridView.Rows[i].Cells[0].Tag as CoBRAMetaField).ID; // get the ID from the row metaField

if (metaFields.Any(field => field.ID == metaFieldID)) // Does it exist?
metaFields = metaFields.Where(field => field.ID != metaFieldID).ToArray(); // Remove it from the new array
else // it doesn't exist
dataGridView.Rows.Remove(dataGridView.Rows[i]); // remove the row
}

// Fill the grid with the remaining metaFields
}


The first run gets initialized correctly



enter image description here



the second run seems to crash, some fields remain empty



enter image description here



when I press the button on this row I get a nullpointer exception. I only get this error when using the "new code" so am I missing something? Is there something I didn't think about?





I will provide a full example here



At first create a DataGridView and Button on the form. Create a file for all required classes and take this snippet



https://pastebin.com/BFmr2ps9



After that fill the forms code with some test data



https://pastebin.com/Yz84Akkj



and now setup the DataGridView logic



https://pastebin.com/qH6kZKZv



I added



dataGridView.AllowDrop = false;
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToOrderColumns = false;
dataGridView.AllowUserToResizeRows = false;


if you just want to copy paste but you can also do it by the forms designer. Have a look at dataGridView.Rows.Clear(); this provides a working example. Comment it out and use the code above to test the incorrect example










share|improve this question
















so when filling my datagridview I normally do something like



    public void FillTable(CoBRAMetaField metaFields)
{
dataGridView.Rows.Clear();

// do something with metaFields
}


Important:




  • CoBRAMetaField is a object with a ID and other stuff


  • Each row in the grid holds a metafield object



My grid gets filled correctly (sorry, the language is german)



enter image description here



When I fill the grid another time I only want to remove the rows with metaFields that don't exist in the new metaFields array. I want this behaviour because when a user selected a value for this row I don't want it to get removed and created again because then the selected value is removed too.



I came up with this



    public void FillTable(CoBRAMetaField metaFields)
{
for (int i = 0; i < dataGridView.Rows.Count; i++) // loop through the grid rows
{
double metaFieldID = (dataGridView.Rows[i].Cells[0].Tag as CoBRAMetaField).ID; // get the ID from the row metaField

if (metaFields.Any(field => field.ID == metaFieldID)) // Does it exist?
metaFields = metaFields.Where(field => field.ID != metaFieldID).ToArray(); // Remove it from the new array
else // it doesn't exist
dataGridView.Rows.Remove(dataGridView.Rows[i]); // remove the row
}

// Fill the grid with the remaining metaFields
}


The first run gets initialized correctly



enter image description here



the second run seems to crash, some fields remain empty



enter image description here



when I press the button on this row I get a nullpointer exception. I only get this error when using the "new code" so am I missing something? Is there something I didn't think about?





I will provide a full example here



At first create a DataGridView and Button on the form. Create a file for all required classes and take this snippet



https://pastebin.com/BFmr2ps9



After that fill the forms code with some test data



https://pastebin.com/Yz84Akkj



and now setup the DataGridView logic



https://pastebin.com/qH6kZKZv



I added



dataGridView.AllowDrop = false;
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToOrderColumns = false;
dataGridView.AllowUserToResizeRows = false;


if you just want to copy paste but you can also do it by the forms designer. Have a look at dataGridView.Rows.Clear(); this provides a working example. Comment it out and use the code above to test the incorrect example







c# winforms datagridview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 8:43







MHComputech

















asked Nov 20 '18 at 15:38









MHComputechMHComputech

19113




19113













  • Link you gave is empty.

    – Aleksa Ristic
    Nov 21 '18 at 12:25











  • okay this is weird, I updated it

    – MHComputech
    Nov 21 '18 at 12:39











  • There is a lot missing from the posted/linked code. There are no definitions for the following variables… CoBRAMetaField, ReleaseSetUpData and FieldName… Without these definitions, finding help may be scarce. In addition, there is a link to some code that does not appear to be used anywhere. Where is the MetaFieldTable class used? Your comment… ”I will provide a full example here but I don't think it's needed” … I think it is needed.

    – JohnG
    Nov 23 '18 at 0:50











  • @JohnG I'm sorry. Now you can take a full working example if someone wants to try to reproduce the project.

    – MHComputech
    Nov 23 '18 at 8:27











  • When I fill the grid another time I only want to remove the rows with metaFields that don't exist in the new metaFields array. - So why you not simply clear the rows and add all rows from the new array?

    – Fabio
    Nov 23 '18 at 8:39



















  • Link you gave is empty.

    – Aleksa Ristic
    Nov 21 '18 at 12:25











  • okay this is weird, I updated it

    – MHComputech
    Nov 21 '18 at 12:39











  • There is a lot missing from the posted/linked code. There are no definitions for the following variables… CoBRAMetaField, ReleaseSetUpData and FieldName… Without these definitions, finding help may be scarce. In addition, there is a link to some code that does not appear to be used anywhere. Where is the MetaFieldTable class used? Your comment… ”I will provide a full example here but I don't think it's needed” … I think it is needed.

    – JohnG
    Nov 23 '18 at 0:50











  • @JohnG I'm sorry. Now you can take a full working example if someone wants to try to reproduce the project.

    – MHComputech
    Nov 23 '18 at 8:27











  • When I fill the grid another time I only want to remove the rows with metaFields that don't exist in the new metaFields array. - So why you not simply clear the rows and add all rows from the new array?

    – Fabio
    Nov 23 '18 at 8:39

















Link you gave is empty.

– Aleksa Ristic
Nov 21 '18 at 12:25





Link you gave is empty.

– Aleksa Ristic
Nov 21 '18 at 12:25













okay this is weird, I updated it

– MHComputech
Nov 21 '18 at 12:39





okay this is weird, I updated it

– MHComputech
Nov 21 '18 at 12:39













There is a lot missing from the posted/linked code. There are no definitions for the following variables… CoBRAMetaField, ReleaseSetUpData and FieldName… Without these definitions, finding help may be scarce. In addition, there is a link to some code that does not appear to be used anywhere. Where is the MetaFieldTable class used? Your comment… ”I will provide a full example here but I don't think it's needed” … I think it is needed.

– JohnG
Nov 23 '18 at 0:50





There is a lot missing from the posted/linked code. There are no definitions for the following variables… CoBRAMetaField, ReleaseSetUpData and FieldName… Without these definitions, finding help may be scarce. In addition, there is a link to some code that does not appear to be used anywhere. Where is the MetaFieldTable class used? Your comment… ”I will provide a full example here but I don't think it's needed” … I think it is needed.

– JohnG
Nov 23 '18 at 0:50













@JohnG I'm sorry. Now you can take a full working example if someone wants to try to reproduce the project.

– MHComputech
Nov 23 '18 at 8:27





@JohnG I'm sorry. Now you can take a full working example if someone wants to try to reproduce the project.

– MHComputech
Nov 23 '18 at 8:27













When I fill the grid another time I only want to remove the rows with metaFields that don't exist in the new metaFields array. - So why you not simply clear the rows and add all rows from the new array?

– Fabio
Nov 23 '18 at 8:39





When I fill the grid another time I only want to remove the rows with metaFields that don't exist in the new metaFields array. - So why you not simply clear the rows and add all rows from the new array?

– Fabio
Nov 23 '18 at 8:39












1 Answer
1






active

oldest

votes


















5





+100









The main problem is in the code for adding rows (taken from the link):



// Fill the grid with the remaining metaFields
for (int i = 0; i < metaFields.Length; i++)
{
MetaField currentMetaField = metaFields[i];

dataGridView.Rows.Add(currentMetaField.Name, null);

DataGridViewRow newRow = dataGridView.Rows[i]; // <-- Problem!

DataGridViewCell metaFieldCell = newRow.Cells[0];
metaFieldCell.Tag = currentMetaField;

(newRow.Cells[1] as DataGridViewAllocationCell).Initialize(releaseSetupData);
}


In the marked line you are assuming that the index of the added row is the same as i, which is true when you start with empty grid, bit not when the grid is updated and some old records are kept.



The proper way of handling it is to not assume the new row index - it is returned by the Add method:



int rowIndex = dataGridView.Rows.Add(currentMetaField.Name, null);

DataGridViewRow newRow = dataGridView.Rows[rowIndex];


This will solve the original issue from the question.



There is also a problem in the remove part of the code - the for loop will miss checking the rows next to the removed ones. Anytime you want to iterate some list and remove items during the iteration, use reverse for loop and RemoveAt:



for (int i = dataGridView.Rows.Count - 1; i >= 0; i--) // <--
{
double metaFieldID = (dataGridView.Rows[i].Cells[0].Tag as MetaField).ID;

if (metaFields.Any(field => field.ID == metaFieldID))
metaFields = metaFields.Where(field => field.ID != metaFieldID).ToArray();
else
dataGridView.Rows.RemoveAt(i); // <--
}


The removal code could further be improved (currently looks inefficient with these Any, Where + ToArray), but at least with the above changes it will work correctly.






share|improve this answer





















  • 1





    Exactly what I needed

    – MHComputech
    Nov 23 '18 at 10:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396499%2fclear-datagridview-duplicate-rows-and-keep-unique-rows%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









5





+100









The main problem is in the code for adding rows (taken from the link):



// Fill the grid with the remaining metaFields
for (int i = 0; i < metaFields.Length; i++)
{
MetaField currentMetaField = metaFields[i];

dataGridView.Rows.Add(currentMetaField.Name, null);

DataGridViewRow newRow = dataGridView.Rows[i]; // <-- Problem!

DataGridViewCell metaFieldCell = newRow.Cells[0];
metaFieldCell.Tag = currentMetaField;

(newRow.Cells[1] as DataGridViewAllocationCell).Initialize(releaseSetupData);
}


In the marked line you are assuming that the index of the added row is the same as i, which is true when you start with empty grid, bit not when the grid is updated and some old records are kept.



The proper way of handling it is to not assume the new row index - it is returned by the Add method:



int rowIndex = dataGridView.Rows.Add(currentMetaField.Name, null);

DataGridViewRow newRow = dataGridView.Rows[rowIndex];


This will solve the original issue from the question.



There is also a problem in the remove part of the code - the for loop will miss checking the rows next to the removed ones. Anytime you want to iterate some list and remove items during the iteration, use reverse for loop and RemoveAt:



for (int i = dataGridView.Rows.Count - 1; i >= 0; i--) // <--
{
double metaFieldID = (dataGridView.Rows[i].Cells[0].Tag as MetaField).ID;

if (metaFields.Any(field => field.ID == metaFieldID))
metaFields = metaFields.Where(field => field.ID != metaFieldID).ToArray();
else
dataGridView.Rows.RemoveAt(i); // <--
}


The removal code could further be improved (currently looks inefficient with these Any, Where + ToArray), but at least with the above changes it will work correctly.






share|improve this answer





















  • 1





    Exactly what I needed

    – MHComputech
    Nov 23 '18 at 10:31
















5





+100









The main problem is in the code for adding rows (taken from the link):



// Fill the grid with the remaining metaFields
for (int i = 0; i < metaFields.Length; i++)
{
MetaField currentMetaField = metaFields[i];

dataGridView.Rows.Add(currentMetaField.Name, null);

DataGridViewRow newRow = dataGridView.Rows[i]; // <-- Problem!

DataGridViewCell metaFieldCell = newRow.Cells[0];
metaFieldCell.Tag = currentMetaField;

(newRow.Cells[1] as DataGridViewAllocationCell).Initialize(releaseSetupData);
}


In the marked line you are assuming that the index of the added row is the same as i, which is true when you start with empty grid, bit not when the grid is updated and some old records are kept.



The proper way of handling it is to not assume the new row index - it is returned by the Add method:



int rowIndex = dataGridView.Rows.Add(currentMetaField.Name, null);

DataGridViewRow newRow = dataGridView.Rows[rowIndex];


This will solve the original issue from the question.



There is also a problem in the remove part of the code - the for loop will miss checking the rows next to the removed ones. Anytime you want to iterate some list and remove items during the iteration, use reverse for loop and RemoveAt:



for (int i = dataGridView.Rows.Count - 1; i >= 0; i--) // <--
{
double metaFieldID = (dataGridView.Rows[i].Cells[0].Tag as MetaField).ID;

if (metaFields.Any(field => field.ID == metaFieldID))
metaFields = metaFields.Where(field => field.ID != metaFieldID).ToArray();
else
dataGridView.Rows.RemoveAt(i); // <--
}


The removal code could further be improved (currently looks inefficient with these Any, Where + ToArray), but at least with the above changes it will work correctly.






share|improve this answer





















  • 1





    Exactly what I needed

    – MHComputech
    Nov 23 '18 at 10:31














5





+100







5





+100



5




+100





The main problem is in the code for adding rows (taken from the link):



// Fill the grid with the remaining metaFields
for (int i = 0; i < metaFields.Length; i++)
{
MetaField currentMetaField = metaFields[i];

dataGridView.Rows.Add(currentMetaField.Name, null);

DataGridViewRow newRow = dataGridView.Rows[i]; // <-- Problem!

DataGridViewCell metaFieldCell = newRow.Cells[0];
metaFieldCell.Tag = currentMetaField;

(newRow.Cells[1] as DataGridViewAllocationCell).Initialize(releaseSetupData);
}


In the marked line you are assuming that the index of the added row is the same as i, which is true when you start with empty grid, bit not when the grid is updated and some old records are kept.



The proper way of handling it is to not assume the new row index - it is returned by the Add method:



int rowIndex = dataGridView.Rows.Add(currentMetaField.Name, null);

DataGridViewRow newRow = dataGridView.Rows[rowIndex];


This will solve the original issue from the question.



There is also a problem in the remove part of the code - the for loop will miss checking the rows next to the removed ones. Anytime you want to iterate some list and remove items during the iteration, use reverse for loop and RemoveAt:



for (int i = dataGridView.Rows.Count - 1; i >= 0; i--) // <--
{
double metaFieldID = (dataGridView.Rows[i].Cells[0].Tag as MetaField).ID;

if (metaFields.Any(field => field.ID == metaFieldID))
metaFields = metaFields.Where(field => field.ID != metaFieldID).ToArray();
else
dataGridView.Rows.RemoveAt(i); // <--
}


The removal code could further be improved (currently looks inefficient with these Any, Where + ToArray), but at least with the above changes it will work correctly.






share|improve this answer















The main problem is in the code for adding rows (taken from the link):



// Fill the grid with the remaining metaFields
for (int i = 0; i < metaFields.Length; i++)
{
MetaField currentMetaField = metaFields[i];

dataGridView.Rows.Add(currentMetaField.Name, null);

DataGridViewRow newRow = dataGridView.Rows[i]; // <-- Problem!

DataGridViewCell metaFieldCell = newRow.Cells[0];
metaFieldCell.Tag = currentMetaField;

(newRow.Cells[1] as DataGridViewAllocationCell).Initialize(releaseSetupData);
}


In the marked line you are assuming that the index of the added row is the same as i, which is true when you start with empty grid, bit not when the grid is updated and some old records are kept.



The proper way of handling it is to not assume the new row index - it is returned by the Add method:



int rowIndex = dataGridView.Rows.Add(currentMetaField.Name, null);

DataGridViewRow newRow = dataGridView.Rows[rowIndex];


This will solve the original issue from the question.



There is also a problem in the remove part of the code - the for loop will miss checking the rows next to the removed ones. Anytime you want to iterate some list and remove items during the iteration, use reverse for loop and RemoveAt:



for (int i = dataGridView.Rows.Count - 1; i >= 0; i--) // <--
{
double metaFieldID = (dataGridView.Rows[i].Cells[0].Tag as MetaField).ID;

if (metaFields.Any(field => field.ID == metaFieldID))
metaFields = metaFields.Where(field => field.ID != metaFieldID).ToArray();
else
dataGridView.Rows.RemoveAt(i); // <--
}


The removal code could further be improved (currently looks inefficient with these Any, Where + ToArray), but at least with the above changes it will work correctly.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 10:59

























answered Nov 23 '18 at 9:07









Ivan StoevIvan Stoev

104k776126




104k776126








  • 1





    Exactly what I needed

    – MHComputech
    Nov 23 '18 at 10:31














  • 1





    Exactly what I needed

    – MHComputech
    Nov 23 '18 at 10:31








1




1





Exactly what I needed

– MHComputech
Nov 23 '18 at 10:31





Exactly what I needed

– MHComputech
Nov 23 '18 at 10:31




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396499%2fclear-datagridview-duplicate-rows-and-keep-unique-rows%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?