Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

DataGridView custom sorting with DataBound

$
0
0

Hello

I fill data grid view in code by bounding data:

            var table = new DataTable();
            table.Columns.Add("Id");
            table.Columns.Add("ExecTime", typeof(DateTime));
            table.Columns.Add("Instrument");

           ...

            ...  adding some columns ...

            var row = table.NewRow();
            row["Id"] = id;
            row["ExecTime"] = creationDate;
            row["Instrument"] = instrument;

            table.Rows.Add(row);

            dgv.DataSource = table;

I like to do a custom comparison for columns like ID (upon clicking on the header) since ID can be once only numbers and once only strings (result is striong from database so I cannot know in advance, I just leave the header as a string type)

Since I am bounding data, I cannot use dvg_SortCompare   Since this event is not firing.

I tried to set column sort mode to programmatic but it did not help to fire this event.

How can I add a custom compactor to my grid columns when using data bounding, so I can control the sorting while clicking on the headers ?

I want to keep setting my DataSource that way

Will appreciate a code sample if it can be done

Thank you

Erez

        



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>