I have some questions about dataGridView control
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.
14 Replies - 2008 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
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
Well... what have you tried, or reasoning for how to do each of those?
#3
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 09 August 2012 - 01:05 PM
If have had tried to create simple DataGridView, you would have discovered that A and B are built into the DataGridView control and work right out of the box.
But then, I could also be lying to you.
You'll need to put together some code to find out.
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.
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
For D you should take a look at the HashSet class
#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:
For D you should take a look at the HashSet class 
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
Why would you not consider DataSource = hashSet.ToList() a solution?
Edit: Oh now I see
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 can't understand you all really
is there no specific code to do this?
I tried some codes like this:
but it didnt work
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
What was not working? Did you step through your code and see the Remove() calls happening?
#9
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 14 August 2012 - 02:19 PM
Hi...
My new method to paste from clipboard to datagridview is:
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
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
Is that intentional that paste will destroy the current data and start adding rows and putting all the data into the first column? What if the original selected text that was put into the clipboard was multiple columns and didn't start at the top left corner of the grid?
#11
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 14 August 2012 - 02:48 PM
don't worry it is intentional.
#12
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 14 August 2012 - 03:36 PM
hey guys I still cant remove duplicate rows from datagridview
give me some codes to do this please
#13
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 14 August 2012 - 04:21 PM
I solved remove duplicates problem now man. it was very easy too..
#14
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 14 August 2012 - 04:32 PM
Good for you! Did you stick with your use of the List or did you choose something else?
#15
Re: [How To] Remove duplicates, Copy rows from dataGridView
Posted 15 August 2012 - 01:15 PM
I used list control for that!
List<string> list = new List<string>();
List<string> list = new List<string>();
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|