Link to home
Start Free TrialLog in
Avatar of Arikael
ArikaelFlag for Switzerland

asked on

Problem with filtering a databound DataGridView

Hi experts

I have a databound DataGridView, which is sortable.
Now I have implemented a copy method with which I can copy rows around. So far so good, but as soon as I filter my DataGridView with RowFilter (respecticly the DataTable) I doesn't work.

The Problem is the line
tRow = krdispo2DataSet.entries.Rows[cRow.Index].ItemArray;

Because cRow.Index refers to the new Index in the DataGridView but it doesn't correspond with the Row entries.Rows[cRow.Index]

Example:
Row1 -> INdex 1
Row2 -> Index 2
Row3 -> Index 3

When filtering out Row2

Row3 gets the index 2 but only in the datagridview in my DataTable it still has Index 3.

How can I achieve my copy-method?
Or how do I get from my datagridview row to the datatable row?

Thanks
DataGridViewSelectedRowCollection sRows = dataGridView1.SelectedRows;
            
            foreach (DataGridViewRow cRow in sRows)
            {
                DataRow test = cRow.DataBoundItem as ;
                tRow = krdispo2DataSet.entries.Rows[cRow.Index].ItemArray;
     
                if(!KrClipBoard.ContainsValue(tRow))
                {
                    KrClipBoard.Add(i, tRow);
                    i++;
                }
            }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arikael

ASKER

Hi, it's an own ClipBoard-Method.
In fact it is just a dictionary.
Why do you need a custom clipboard method?  What does it give you that GetClipboardContent doesn't?

Bob
Avatar of Arikael

ASKER

I was able to easily copy my rows around (the built in method seperated them with tabs)
I know that it would be a pretty handy thing, but unfortunately the whole program is based in my own ClipBoard and until I have time to migrate to the built in mechanism I just need to fix my own mechanism.
Avatar of Arikael

ASKER

Well, well you convinced me to rewrite my copy-paste mechanism ;-)
After some time it now works with the internal clipboard
Here is an interesting link:
http://jrwren.wrenfam.com/blog/2007/09/08/datagridview-databound-copy-paste-drag-drop/

Avatar of Arikael

ASKER

TheLearnedOne, is it OK when I split the points between us, say 50/50?