|
I don't quite see how that fits (the MSDN documentation on this subject really sucks). I have a SortedList bound to a DataGridView and I want the element(s) of the SortedList to be deleted when the user deletes the related row in the DataGridView . So where do I implement INotifyCollectionChanged ? Or are you saying that I should provide my own collection class as the BindingSource ?
I must get a clever new signature for 2011.
|
|
|
|
|
Richard MacCutchan wrote: Or are you saying that I should provide my own collection class as the BindingSource?
Yup. I'm usually using an ObservableCollection as it already has this functionality, not a SortedCollection. To quote the site;
"However, to set up dynamic bindings so that insertions or deletions in the collection update the UI automatically, the collection must implement the INotifyCollectionChanged interface. This interface exposes the CollectionChanged event that must be raised whenever the underlying collection changes."
I are Troll
|
|
|
|
|
That all sounds fine, and I just found an article which covers this subject in some detail. However, my issue is that I want to be notified when the content of the DataGrid changes (user deletes a row) so I can update the contents of the data source (i.e. the collection). Both of the aforementioned features seem to be about notifying the UI when the underlying collection changes, but in my case the collection will not change on its own.
I must get a clever new signature for 2011.
|
|
|
|
|
Richard MacCutchan wrote: my issue is that I want to be notified when the content of the DataGrid changes (user deletes a row) so I can update the contents of the data source (i.e. the collection).
You were talking about a DataGridView earlier. The DataGrid has a RowDeleting[^] event, the DataGridView has a OnRowsRemoved[^].
Just dropped a grid on a form, and printed the count of the DGV-rows in that event. It does not alter the collection, only the rows in the DGV itself. ..dunno why, but something tells me that this event is probably not being raised in your project
Richard MacCutchan wrote: Both of the aforementioned features seem to be about notifying the UI when the underlying collection changes
Yes, a biased mind
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: You were talking about a DataGridView earlier.
I've been talking about it throughout this thread; indeed it is part of my subject line.
Eddy Vluggen wrote: something tells me that this event is probably not being raised in your project
Which is the entire issue I am struggling with. I delete some rows in the DataGridView but nothing changes in my data source (the SortedList ). I thought data binding was there to solve problems, not to create them!
To recap: I have a SortedList bound to a DataGridView . When I delete a row from the DataGridView I expect the corresponding entry to be removed from the SortedList but I cannot find any examples or documentation to help explain why it doesn't happen. I'm somewhat surprised that no-one has come across this problem before.
I must get a clever new signature for 2011.
|
|
|
|
|
Richard,
Can you show the code that binds your SortedList to the DGV?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
Henry, the following is the method that sets up the DGV.
private void ShowVolunteers(SortedList<string, Volunteer> vols)
{
volList = vols.Values.ToList();
bindingSource.DataSource = volList;
volunteerGrid.DataSource = bindingSource;
volunteerGrid.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
volunteerGrid.AutoGenerateColumns = true;
volunteerGrid.Focus();
}
The Volunteer class contains three string values which show up fine in the DGV. I tried adding the INotifyPropertyChanged interface to my Volunteer class (as suggested by Eddy) but it never gets called, since the actual objects do not get changed. The only 'changes' I want to allow is for the user to delete some rows from the DGV, and the data source to be updated automatically.
To be honest, I would not spend too much time on this as I have a work around, which is to use the DGV rows that remain to get the final results I need. However, if you can spot an obvious fix I would certainly be interested in knowing about it.
I must get a clever new signature for 2011.
|
|
|
|
|
I just wanted confirmation of how you were binding before I made my suggestion in order to prevent my usual faux pas.
You need to change the type of your volList to BindingList<Volunteer>
Then in your ShowVolunteers()
volList = new BindingList<Volunteer>(vols.Values.ToList());
*****NOTE****
This will propagate the deletion only as far as the bindingSource NOT to vols . To make this useful you will need to rebuild vols from bindingSource.List at an appropriate point.
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
Thanks, I'll give it a try and let you know.
I must get a clever new signature for 2011.
|
|
|
|
|
Thanks Henry, it works perfectly.
I must get a clever new signature for 2011.
|
|
|
|
|
In DoWork() function the thread is different from the main thread and Thread.CurrentThread.CurrentCulture is default one similar to Application.CurrentCulture
Is it possible to change worker culture to UI culture without passing it in arguments?
Чесноков
|
|
|
|
|
Why not use CultureInfo.CurrentUICulture ?
|
|
|
|
|
That is the property returning current thread culture settings that is UI thread.
Чесноков
|
|
|
|
|
A new thread receives culture/UI culture from the Windows system - in my opinion that's a bug (but Microsoft may see that differently). I use to set the UI culture with a value from the .exe.config file - that can also be applied in a newly started thread. Otherwise, have a (static) member in some class/object you can access from the background worker.
|
|
|
|
|
Bernhard Hiller wrote: I use to set the UI culture with a value from the .exe.config file - that can also be applied in a newly started thread
I do that in UI application, but background worker is in class library which is used by UI application.
Class library is not supplied with config file by intent.
I know it is possible to pass an argument to a thread or access its class variable or static field set up externally but I wonder if it was possible to getbackground thread handle and change its culture.
Чесноков
|
|
|
|
|
Hello Everybody,
If my application is running in administrator Previledge (Run as admin) then i am executing any application from this
application.The Executed application is also run with Administrator Mode. But i want to run it with current user Previledge.
pls describe me how can it possible.
Thanks
If you can think then I Can.
|
|
|
|
|
eg_Anubhava wrote: But i want to run it with current user Previledge.
Only the user can run processes under his privileges, if you're an admin you'll spawn processes with admin-privileges. You can use the Proces class to spawn a process under a different account, but you'll need the users' name and password. Point is that your process isn't in the users' space, and it has to provide the right credentials before it's allowed there
I are Troll
|
|
|
|
|
I have decided that I need a better way of validating data.
I currently have various objects that can validate information, for example:
if(TextBoxValidator.IsValidTextBox(tbText))...
Also I tend to use the Debug.Assert() methods often, making sure that null or invalid states of variables are shown.
Its starting to get repetitive when I validate:
if(fileDetails.ToString() == string.Empty || map == null) return Common.ReturnResult.Failed;
if(map.StaticImages == null || map.Tiles == null) return Common.ReturnResult.Failed;
if(map.Infomation.Columns == 0 || map.Infomation.RootContentFolder == string.Empty || map.Infomation.Rows == 0 || map.Infomation.TileSize == 0)
return Common.ReturnResult.Failed;
There must be a better way to validate methods input and such than this!
Any suggestions, Thanks
|
|
|
|
|
One way is to avoid nulls in the first place, but if you need to check , here is a start, it is longer but clearer to read:
...
bool Success(footype map)
{
if(map.StaticImages == null)
return false;
if(map.Tiles == null)
return false;
if(map.Information.RootContentFolder == "")
return false;
if(map.Infomation.Rows == 0)
return false;
if(map.Infomation.TileSize == 0)
return false;
}
public Foo()
{
if(fileDetails.ToString() == string.Empty)
return Common.ReturnResult.Failed;
if(map == null)
return Common.ReturnResult.Failed;
if(!Success(map))
return Common.ReturnResult.Failed;
return Common.ReturnResult.OKorWhatever;
}
Can you change the map object? If so the Success Status is probably better off there as a property, you could also break this down into further sub-properties such as HasImages , HasInformation etc
|
|
|
|
|
May be better to use CASE statement.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
What about an "IValidable " interface defining a method "Validate() "?
When "map" and its properties implement it, you could simply call map.Validate() which would encapsulate that logic there.
|
|
|
|
|
Thanks for the reply,the problem is that I would have allot of validation objects everywhere, which wouldn't be very fun to use...
|
|
|
|
|
HOw about
public bool CheckForNulls(object[] thingsThatShouldntBeNull)
{
return thingsThatShouldntBeNull.TrueForAll(x => x != null);
}
CheckForNulls(new object[]{dumbshitCoderField1,dumbShitCoderField2);
|
|
|
|
|
Anyone know why isn't this working?
The line oSheet.Cells[row, column] = data; works correctly and it writes to incrementing columns and rows correctly, but I would like it to see if data contains a \\ and then make it a hyperlink if it does.
Thanks for reading.
oSheet.Cells[row, column] = data;
if ((data.Contains(@"\\")) && (createSheet == false))
{
oSheet.Hyperlinks.Add(oSheet.get_Range(row, column), data, System.Type.Missing, System.Type.Missing, data);
}
|
|
|
|
|
The main problem is the way you are adding the hyperlink.
Instead of Hyperlinks.add you could try Range.ApplyFormula .
Obviously you have to define the formula...
string filexl = @" C:\NewFile.xls";
Workbook wbnew = new Workbook();
Worksheet wsnew = wbnew.Worksheets.Add("New");
wsnew.Rows[0].Cells[0].ApplyFormula(@"=HYPERLINK(""http://www.codeproject.com"",""Urgentzzzz"")");
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|