14 Replies - 2179 Views - Last Post: 15 August 2012 - 01:15 PM
#1
[How To] Remove duplicates, Copy rows from dataGridView
Posted 09 August 2012 - 12:07 PM
A- How can I paste from clipboard to datagridview
B- How can I copy selected row to clipboard
C- How can I remove rows which not starts with "http://"
D- How can I remove dupliate rows
I had 10 problems like that, I figured out 6 of them.
I did much research about these 4 issues, but I can't find any useful information.
Finally I realized that; dataGridView is the most hard to use control in C# visual studio.
Help me please. I really need help urgently. Thanks.
Replies To: [How To] Remove duplicates, Copy rows from dataGridView
#2
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 09 August 2012 - 12:24 PM
#3
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 09 August 2012 - 01:05 PM
But then, I could also be lying to you.
As for filtering the rows for particular data and duplicates. The DataGridView will display whatever you give it in the DataSource property. It's up to you what that data will be.
#4
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 09 August 2012 - 01:57 PM
#5
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 09 August 2012 - 02:44 PM
CasiOo, on 09 August 2012 - 01:57 PM, said:
Good suggestion! Unfortunately, the class doesn't implement IList, IListSource, IBindingList, IBindingListView or any other interface that the DataGridView's DataSource needs to display data.
We're not completely hosed, though, one could easily create a class that implements an IListSource and that contains a HashSet. (And no, setting DataSource = hashSet.ToList() is not a solution unless the DataGridView is set to be read only.)
#6
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 09 August 2012 - 03:02 PM
Edit: Oh now I see
This post has been edited by CasiOo: 09 August 2012 - 03:08 PM
#7
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 09 August 2012 - 06:19 PM
I tried some codes like this:
List<string> list = new List<string>();
for (int i = 0; i < dataGridView1.Rows.Count; i++ )
{
string str = dataGridView1.Rows[i].Cells[0].Value.ToString();
if (!list.Contains(str))
list.Add(dataGridView1.Rows[i].Cells[0].Value.ToString());
else
{
dataGridView1.Rows.Remove(dataGridView1.Rows[i]);
}
}
but it didnt work
This post has been edited by JackOfAllTrades: 14 August 2012 - 04:48 PM
Reason for edit:: Added code tags
#8
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 09 August 2012 - 06:33 PM
#9
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 14 August 2012 - 02:19 PM
My new method to paste from clipboard to datagridview is:
StreamWriter sw = new StreamWriter(@"Config/paste");
string t = Clipboard.GetText();
sw.Write(t);
sw.Close();
StreamReader sr = new StreamReader(@"Config/paste");
dataGridView1.Rows.Clear();
while (sr.Peek() >= 0)
{
DataGridViewRow row = dataGridView1.Rows[dataGridView1.Rows.Add()];
row.Cells["Column1"].Value = sr.ReadLine();
}
sr.Close();
File.Delete(@"Config/paste");
It works great and TOOO fast for me. But I wonder that what do you guys think of my new method? Is this a good method? Thanks
#10
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 14 August 2012 - 02:29 PM
#11
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 14 August 2012 - 02:48 PM
#12
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 14 August 2012 - 03:36 PM
#13
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 14 August 2012 - 04:21 PM
#14
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 14 August 2012 - 04:32 PM
#15
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 15 August 2012 - 01:15 PM
List<string> list = new List<string>();
|
|

New Topic/Question
Reply



MultiQuote







|