|
Hi Dave, thanks for looking, I am just trying to understand DataGridView. So a column with icons on every row is what I am after.
Having said that, I'll go and check out the link you have provided as well.
============================================================================
Edit:
Here's how I got it to work.
DataGridViewImageColumn img = new DataGridViewImageColumn();
img.Name = "img";
img.HeaderText = "Dice";
img.ValuesAreIcons = true;
dgvScore.Columns.Add(img);
Icon image0 = Properties.Resources.diceSix;
dgvScore.Rows[0].Cells["img"].Value = image0;
Icon image1 = Properties.Resources.diceOne;
dgvScore.Rows[1].Cells["img"].Value = image1;
modified 29-Feb-16 2:03am.
|
|
|
|
|
The documentation is really poor with the Rx functions:
Observable.Join(TLeft, TRight, TLeftDuration, TRightDuration, TResult) Method (System.Reactive.Linq)[^]
Got a little bit better by reading Lee's online book[^] and seeing the comments below this[^] Channel 9 video. So I finally managed to get something working (it is just a timer that tells for how long the left mouse button was pushed down):
var MouseDown = Observable.FromEventPattern<MouseButtonEventArgs>(this, "MouseDown");
var MouseUp = Observable.FromEventPattern<MouseButtonEventArgs>(this, "MouseUp");
var LeftMouseButtonPressedDuration = Observable.Join(
MouseDown
.Where(evt => evt.EventArgs.ChangedButton == MouseButton.Left)
.Select(_ =>
{
DateTime now = DateTime.Now;
return now;
}
),
MouseUp
.Where(evt => evt.EventArgs.ChangedButton == MouseButton.Left)
.Select(_ =>
{
DateTime now = DateTime.Now;
return now;
}
),
MouseDownTimeStamp => MouseDown,
MouseUpTimeStamp => Observable.Empty<DateTime>(),
(TimeDown, TimeUp) =>
{
TimeSpan MousePressedDuration = TimeUp - TimeDown;
return " Total duartion is: " + MousePressedDuration.ToString(@"ss\:fff");
}
);
LeftMouseButtonPressedDuration.Subscribe(evt =>
{
txtMainWindow.Text += Environment.NewLine + evt.ToString();
});
The two first sections are really easy to grasp, as well as the last function. But it is the third and fourth function inside Join that I really don't understand or even fully comprehend how to use. I assumed that it had something to do with how the events were interpreted. I assume that the 4th section,
MouseUpTimeStamp => Observable.Empty<DateTime>()
, is telling the compiler that when a new mouse down event happens, the mouse up will be cleared. If I changed the code slightly and put Publish() behind it:
MouseDownTimeStamp => MouseDown.Publish(),
MouseUpTimeStamp => Observable.Empty<DateTime>(),
It stored all the times since the first mouse down was pressed. Like a cross contry ski race where everyone starts at the same time, but arrive at the goal at different times.
So I tried to re-create the code that Lee had in his online book:
var Interval_50ms = Observable.Interval(TimeSpan.FromMilliseconds(50))
.Take(10);
var Interval_100ms = Observable.Interval(TimeSpan.FromMilliseconds(100))
.Take(5)
.Select(i => Convert.ToChar(i + 65).ToString().ToUpper());
var tt = Observable.Join(
Interval_50ms,
Interval_100ms,
s => Interval_50ms,
c => Observable.Empty<char>(),
(s, c) => { return s.ToString() + ", " + c.ToString(); })
.Subscribe(Console.WriteLine);
The output was just plain bizzare, at least to me:
3, A
3, A
3, B
6, D
8, E
I expected something like:
0, A
2, B
4, D
6, E
or at least an interval 2 between each char. What Am I doing wrong and/or what have I not understood here?
|
|
|
|
|
After some testing I seem to have found my answer:
var Interval_50ms = Observable.Interval(TimeSpan.FromMilliseconds(50))
.Take(10);
var Interval_100ms = Observable.Interval(TimeSpan.FromMilliseconds(100))
.Take(5)
.Select(i => Convert.ToChar(i + 65).ToString().ToUpper());
var Result = Observable.Join(
Interval_50ms,
Interval_100ms,
s => Observable.Never<Unit>(),
c => Observable.Empty<Unit>(),
(s, c) => { return s.ToString() + ", " + c.ToString(); })
.Subscribe(Console.WriteLine);
The two streams seems to start arbitrary, I cant seem to get the lined up properly, as it sometimes it will start at 0, A and other times 1, A . I think that the stream that is an s => Observable.Never<Unit>() just tells the compiler to store all the values that has come as a number into an Observable<T> , and by setting the c => Observable.Empty<Unit> it will basically publish all values it has stored in s and combine these with the new single value that it found at c .
This was also a point that confused me, that the s and c will return singular value at the time, but can be of the stream type of Observable<T> . So when I get the result in (s, c) => ... they are of type <T> .
By using the type Observable.Empty<Unit> if told it to just get me the next new value. The code seem to say: once you get a new char into c, print all the values in s with the value c.
Trying to understand how to create the latest value of s with the next value of c was however a bit tricky:
Observable.Join(
Interval_50ms,
Interval_100ms,
s => Interval_50ms,
c => Observable.Empty<char>(),
(s, c) => { return s.ToString() + ", " + c.ToString(); })
.Subscribe(Console.WriteLine);
This seem to produce some code that had some racing conditioning to it, so the results were a bit unstable.
|
|
|
|
|
I've seen you take quite some interest in Rx.
My 0.02$ - a lot of people (me included) would benefit from your research - why not write an article about it?
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
The problem I have is that it takes me forever to figure out stuff, as the documentation is pretty poor sometimes. The problem here is that I still have some questions about Observable.Join, so I feel that I can't write it yet.
|
|
|
|
|
I completely understand. That's one of the reasons that kept me from learning Rx a while ago.
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
|
Awesome, will read in a bit!
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
I have a grid view that will be populated with a fairly large amount of data. It will average 1500-2000 lines the first run, and will be only increasing from there. I have been looking into ways to filter the data for the user. I was hoping to use a text box for each column of the grid and allow the user to filter the information by multiple columns at a time. I have seen some projects use jquery AJAX to do this, but it requires calling to the database every time a value is entered into the text boxes. Has anyone approached a problem like this and found a way to handle it with out excessive calls to the database?
|
|
|
|
|
|
i have encryption and decryption in code.Encryption is working fine but decryption is not working
here is code i am using to decrypt passowrd
public static string Decrypt(String text)
{
SymmetricAlgorithm algorithem = DES.Create();
ICryptoTransform transform = algorithem.CreateEncryptor(key, iv);
byte[] inputbuffer = Convert.FromBase64String(text);
byte[] outputbuffer = transform.TransformFinalBlock(inputbuffer, 0, inputbuffer.Length);
return Encoding.Unicode.GetString(outputbuffer);
}
can any help me to work it out
|
|
|
|
|
|
this is to retrieve password from database
|
|
|
|
|
Well you are doing it wrong. If you encrypt passwords then they can be decrypted, which makes them insecure. You should only ever use hashed values to store passwords. I just hope your system is not used by my bank.
|
|
|
|
|
What Richard is saying is that there is an established, secure system for passwords that works.
- Pick a hashing function. (salted SHA256/512 is a fair pick right now)
- When a user sets a password, derive the hash and store that in the database.
- When a user authenticates, hash the password that they enter using the same function, and compare it to the database entry.
This prevents a litany of sins. Mainly, the plaintext of the password is only known by the user, sysadmins cannot grab it out of the database and crack it. Hackers cannot get credentials by compromising a database. Just make sure that you properly protect the password in transit from the user to your application.
Oh, and make sure to salt. Unsalted hashes may as well be plain text.
|
|
|
|
|
|
You also need to post how you are encrypting it. Essentially they are opposites more or less.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
No, he needs to forget about encryption and concentrate on doing the right thing the right way.
|
|
|
|
|
Richard MacCutchan wrote: No, he needs to forget about encryption and concentrate on doing the right thing the right way. It's good to point out a better way to do things. But people do not always have the option to change how things are done and we should still be willing to help.
For example, what if OP is also encrypting other information. OP will also have problem decrypting it and will need help. So, point out the better way for passwords but still help the person out.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I appreciate that you are only trying to help, as you always do. But the problem, as I see it, is as follows. Three of us respond by telling the OP that he is doing it wrong and needs to understand how to deal with passwords properly. You then post a response to his original question saying, "hey, I can help you with decryption". The net result being that OP's brain says, "to hell with those guys, here is someone who is going to help me decrypt my passwords". So yet another system has the potential to go live with compromised security.
|
|
|
|
|
We'll both help in our own ways then.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hi ,i have a questions ,and i don't know how to handle it.
I have a double array named array1=new double[100], and each element is function result, like array1[0]=fun(0),array2[1]=fun(1)...
each element is positive or negative, and generally speaking, a[0] to a[n] is positive, and a[n+1] to end is negative, so how can i get n ? i need efficient algorithm, like divide-and-conquer method for example...
and case 2: if near the end i get wrong result, for example, a[90] is +,how can i get the first negative index n ?
|
|
|
|
|
In case one, a simple Binary search algorithm - Wikipedia, the free encyclopedia[^] should do it, assumign there is no "bad" data.
When you data goes bad, that's different, and it becomes necessary to actually search the whole array - if there is one bad value, then it's likely there are more.
But the alternative to both is to to it all while you fill the array - since that is already a time consuming process (compared to a search of the results) adding a little extra checking to find the first negative as you fill the values is trivial, and allows you to cope with the second case as well.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I'm dynamically constructing query expressions and getting an unexpected error from EF when the query gets executed. So I turned on .NET source stepping, VS downloaded all the debug symbols and steps into anything but the EF query execution. I googled for this phenomenon but didn't find anything "stepping into EF"-specific. Do you have any suggestions?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|