My dataGridView is fetching data from an xml file, the AutoRefresh option will reload the data after an interval of 1 minute.
Let's assume that the user had "Checked" the AutoRefresh checkBox and had minimised the WinForm.....
Is it possible that I can "restore" my winForm as soon as the dataGridView gets updated with new data (Autorefresh)????

6 answers
To restore a minimized form, you can use this code:
answered one year ago by:
17279
412
what I was not able to figure out was: How can I find out that the DataGridView had got new data? How to know when the dataGridView is updated with new row or updated cells?
I might not have used the best practise.... but this worked!!!!
I did something like this:
I need another help...... How can I sort multiple columns in the dataGridView????
Sort first on "Date" then sort second on "Time" ?????
PS: I'm using xml as the dataSource for this dataGridView.
answered one year ago by:
412
17279
If you want to sort the DGV on multiple columns then you'll have to write your own IComparer and pass an instance of it to the Sort() method. If you're recoiling in horror, this isn't as difficult as it sounds - see http://msdn.microsoft.com/en-us/library/wstxtkxs(VS.90).aspx for an example using a couple of string columns. If both your columns contain DateTime values, then you'll need to use the DateTime.Compare rather than the String.Compare method.
I tried something like this:
And as per ur previous comment I added this line in Form1_Load
I'd also added the new class added for sorting multiple columns
But it's giving an exception "DataGridView is data-bound. The control can not use the comparer to perform the the sort operation".
Guidance please..........
answered one year ago by:
412
17279
This method only works if you populate the DGV manually. If you're using databinding (i.e. setting the DataSource property) then you have to sort the data using an IComparer or other approach BEFORE you bind it to the DGV. Also, unless dates are displayed in yyyy/MM/dd format, your RowComparer won't work as it stands because you're sorting DateTime values, not their string representations.
412
Ohhh..... and u were saying "If you're recoiling in horror, this isn't as difficult as it sounds".
412
But the default format is System.String.Compare(string A, string B), so I didn't changed anything there.
I just thought of an easy way to do this without writing your own IComparer.
If the first two columns are named "date" and "time", then try the following:
EDIT - see comments below
The only way I can think of doing this is to create an extra 'DateTime' column in the DataTable which combines the 'Date' and 'Time' columns, sort on that and then hide it in the DGV.
An advantage of this approach is that we can then use another overload of the DGV's Sort() method which sorts on a single column and can still be used even if the DGV is databound.
answered one year ago by:
17279
412
this is not sorting..... my xml is something like this: <?xml version="1.0" encoding="utf-8" ?> <CNI> <news> <Date>05 Apr 2010</Date> <Time>16-06</Time> <News>Just tried to create this thing.</News> </news> <news> <Date>06 Apr 2010</Date> <Time>10-36</Time> <News>Just an entry to test.</News> </news> </CNI>
17279
The problem is that the XML file doesn't contain schema info and so the Date and Time nodes are inferred to be of type string rather than DateTime. Consequently, the DataView isn't sorted properly. I haven't time right now but I'll see if I can come up with something and get back to you later.
412
No problem at all, take ur time. Let's assume that I'm still using my previous code to fetch xml file and fill the DataSet. if u can just tell me "how can I get the value of the 1st cell in all rows of the dataGridView??? I'm planning to change the background color of that row who's date (1st cell) is today.
17279
Please see my edit.
412
That's WONDERFUL..... But Sorting is not only the case, a user will be updating these xml news file. And u know that when somebody else needs to do some work.... they want it to be Simplest and minimum. So I was trying to keep the interface & Input requirement to the minimum. Fo input purpose I was thinking that we can do something like this: <news> <Date_Time>06-5-2010, 10:36</Date_Time> <News>Just an entry to test.</News> </news>. I was thinking that it would be possible to programmatically input the current date & time in 24Hr format. Any better way u suggest????
17279
Even if you did that, it would still be inferred to be a string rather than a DatetTme and so you'd again have to create a separate DateTime column for sorting purposes. As far as I can see, the only way you can infer it to be a DateTime is to include the schema in the xml file and (worse) express all DateTimes in ISO 8601 format which is not very friendly.
412
This is sad.... Can't we sort strings to make life easier.... ??
412
How can I get the Row count of this dataGridView in Interger?????
17279
You can only sort on strings if you don't mind expressing the date in a format which has the year first such as yyyy-MM-dd HH:mm.
17279
The Row count can be found from the expression dataGridView1.Rows.Count. However, if you're allowing the user to add new rows, then this expression will include the new empty row so you need to be careful to exclude that (as I did above) when iterating through the rows.
Thx for the help....... Plz ignore that previous comment (comparing columns).
Somehow I'm again not able to add comments
I've made a small change in xml file to make a HUGE impact.
In previous code we were using
I'm having a doubt that in present scenario if I want to fetch "ALL" news.... then how should I go ahead with that?
answered one year ago by:
412
17279
You can only bind the DGV to one DataTable at a time. If you wanted to have a separate DataTable for each month, then you'd need a ListBox (say), listing the months, and the DGV would then display the entries for the currently selected month. If you wanted to display ALL months at once, then you'd need to create a separate DataTable programatically which merged all the others and then bind to that.
412
I'm trying to write back the DGV into the xml but I'm not able to do so...... Where am I making the mistake?????? DataSet ds = new DataSet(); this.dataGridView1.Visible = true; this.dataGridView1.Columns.Remove("DateTime"); ds=(DataSet)(dataGridView1.DataSource); DateTime column is added in the last but it remains in the xml file.....
You need to delete the extra column from the dataset, not from the DGV.
Also, unless you're rewriting to the file just before the application closes, then I'd copy the dataset first, remembering that the DGV is still bound to the original one.
answered one year ago by:
17279
412
Boss liked the utility. I got an official idea to develop :)....................... That one would be very different, but let me see how will I start with it. This one is similar to the above application. Difference is I need not have DateTime thing, Only date is required which I think will simplyfy the process. But... But..... the New development is that I'm supposed to have a Project column now. so the xml will become something like <cni> <Project1><Date></Date><Rev></Rev><Document></Document></Project1></cni>..... .... ..... and the contents (Display) of this xml should be restricted to different users. Means a user can see only his Projects.....
412
I'll start a NEW thred for this one.... Thx Vulpes soooooooooooooooooooooo much for every bit of help :)