|
I have no idea what your form looks like, but you could just use a TableLayoutPanel, properly configured of course, and put your DGV and Combo in adjacent rows. If setup correctly, you can eliminate the Resize code entirely.
The only time I've seen the "DataGridViewComboBox cell value is not valid" is when the value in the combo is not valid for the bound field. You could ignore it, but keep in mind that the error you're seeing is an exception and exceptions are VERY expensive to throw. Your code performance will suffer because of it.
|
|
|
|
|
Thanks for that advice. I will look into a Table Layout Panel and see if that will work out. 
|
|
|
|
|
Also, why are you adding a combobox to the DGV when there's a combobox column available??
It seems you're using the DGV as a kind of storage for your data instead of binding the DGV to a DataTable object and storing the data in there.
|
|
|
|
|
Good question.
Well, I have set the column in question as a combo box using the DGV edit column property page. If you will notice in my code I use a variable of the name of newComboBox which is a data type of "DataGridViewComboBoxCell". What my intention was to populate each row with the same data, but each row will have a different selection that can be saved. With that being said if the user saved that layout when the file gets opened I will populate the DGV with the same data, but the currently selected item would be different (if the user decided to select different items). I hope that makes sense.
My thinking was in order to populate each row with pre-defined data the best option was to use the variable newComboBox as mentioned above and reference that to the DGV. It functions as I expected, but the added benefit (sarcasm) I get is the thrown exceptions as I mentioned in my previous response.
You're correct that I am using the DGV differently then I guess what's intended in doing. (Maybe this is root of my problem?). I don't have a DataTable for which it can refer to.
|
|
|
|
|
Dave is right, threading won't help you. Remove it, and the Monitors. And put all painting code in the Paint handler. Here[^] is an article that gives the fundamentals; the examples use C#, the concepts are identical in VB.NET though.
|
|
|
|
|
I had a problem with something about my picturebox.paint_event constantly firing. Still to this day I am clueless as to why. I was about to post a new question in the vb discussion when I came across this discussion I started a while back. I wanted to let you know that link that you posted solved my problem.
My program would draw primitive shapes (circles, lines, letters, etc) onto a picturebox using gdi+, but like I said the picturebox.paint_event would always trigger. This would peg one of my cpus at 100%, rather annoying. After making the changes that website you posted suggested the results are like night and day. Instead of the picturebox I used a panel and the paint_event only triggers when it should be triggered.
I just wanted to circle back and say thanks! Even though quite some time has passed 
|
|
|
|
|
Forgive me I am a retired doctor and am just learning programming. I am playing with a small routine that will display number, and signs in rolling boxes to create a kind of slot machine effect to teach my granddaughter math.
I have listed the code below I am having a problem with. It will display the first set of pictures when I click on the button but will not display the pictures in the image list as it randomly selects them.
When I click the next three are moved and displayed but using a loop or a go to statement never works.
I do set the pictures to a default value prior to this routine.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Reel As Integer
Reelspin:
Dim intpic As Integer
Dim rand As New Random
intpic =rand.Next(0,ImageList3.Images.Count)
Me.PictureBox3.Image = PictureBox2.Image Me.PictureBox2.Image = PictureBox1.Image Me.PictureBox1.Image = ImageList3.Images(intpic)
Reel = (Reel + 1)
If Reel < 10000 Then goto respin
End Sub
I would be very great-full for any help I want to display the pictures as they change in real time.
|
|
|
|
|
First, using goto is akin to farting loudly in church. You just don't do it.
It doesn't work because your code is hogging the UI thread. This means that since your code isn't giving up control the UI thread can't process the PAINT messages that are coming into your app from Windows (updating the image you see on screen). The end result it that you only see the last image you set when your loop is done.
How do you get around this?? Forget the loop and use a Timer. Set the Timer to fire an event every 250 milliseconds or so. Start (enable) the Timer in your button Click event.
When your code to change which frame you see will be in the Timer.Tick event. Something like this:
Private RNG As New Random
.
.
.
Private Sub MyTimer_Tick(...) Handles MyTimer.Tick
Dim index As Integer = RNG.Next(0, ImageList3.Images.Count)
PictureBox3.Image = PictureBox2.Image
PictureBox2.Image = PictureBox1.Image
PictureBox1.Image = ImageList3.Images(index)
End Sub
You don't need to put Me. in front of everything.
|
|
|
|
|
First THANK YOU for responding so quickly...
Second I feel a dumb as a rock. Being a retired
doctor I thought programming would come a lot
easier to me.
I understand part of what your saying...
That being I have to give the the system time to
update the screen to allow the images to be painted
and seen before the next image appears.
Also I understand how to add the timer and set the value however, I am a little perplexed as to how to call the timer. Do I need to loop back each time until all the images have been displayed? And if so how and where do I call the timer to allow the delay? That is a delay after each image or just after each set?
Thanks again
|
|
|
|
|
A timer periodically fires an event, that is its job. And it is your code that deals with such event, that is what the "Handles myTimer.Tick " says in Dave's code snippet. So you don't provide the looping, the timer does that; you just tell it what to do each time.
|
|
|
|
|
OK now I am more lost than ever...
I understand that I need to slow the process down
and let the images be painted to the screen so each can be seen before it continues to the next image.
I also understand that the timer will do that...
Where I am getting lost is how you call the timer into action. I created it and set the value as suggested to 250. But do I place the code line prior to displaying any image images?
Further, I need to repeat this paint 1,2,3
over and over until the a random timer stops the images from being chosen and displayed.
At this point every time I press the SPIN KEY, or button as it were the images are selected, displayed and with every click they move down one image. Placing a loop, jump or any other kind of repeating function kills the display of any image until the last one, then that is displayed, hence the need for a delay so they can be painted.
If I understand right the timer only need to be activated once and it will fire on its own after that correct? Or do I need to reset the value after each use?
Thanks...
|
|
|
|
|
timer 101:
- create an instance of System.Windows.Forms.Timer
- set its Interval in milliseconds
- give it a Tick handler (a method that "Handles ...Tick"
- launch it by calling its Start method
- DONE: the tick handler will be executed periodically until you explicitly stop the timer.
Yes, the .NET timers are "free running" by default: once started, they keep "ticking" until you stop them. And you can change their Interval any time you like, in case you want the wheels to slow down.
any delay you want is built in the timer, that is what the Interval property is for (e.g. for your alarm clock, the Interval would be 24 hours).
What you need is a "state variable", i.e. one or more data items that know how far your machine has moved. Say you start the timer inside the SpinButton_Click handler, and set a variable "digit" to 0.
Now inside the timer's Tick Handler, you increment "digit" (up to its maximum value, then reset it to zero), and order a repaint of your Form (or a reload of an image in a PictureBox), where the new content depends on "digit". That will make the wheels spin, until you decide it was enough, so you probably need a random number "maxTicks", and after maxTicks ticks of the timer, you stop the timer, and hence the wheels.
|
|
|
|
|
Thanks for all the help
I think I have it now I am going play around with what you have given me and see if I can get it running the way I want.
You have all been life savers...
A not so lost friend...
Dr. Johnson
|
|
|
|
|
I'd like to amplify the other excellent answers a bit.
I am a VB 6 programmer so I may refer to methods that have changed but they are described in the Help.
You need to have a timer to slow down the process.
Whenever the timer acts, you need to
1 - load the image into the picturebox picturebox.image=...
2 - refresh the picturebox by calling the Refresh picturebox.refresh (may also be Redraw check the Help)
3 - let Windows process the action. application.DoEvents
Its the DoEvents directive that causes Windows to suspend the current thread and process all messages i.e. the picturebox.Refresh method will be executed.
Search the DoEvents in Help for an excellent discussion and sample code. The sample uses a click event from a button but you can just as easily control the process with a timer.
Your images should change whenever the timer ticks.
Murray
|
|
|
|
|
A big THANK YOU to everyone who helped with my problem.
After taking everyone's suggestions I played around with the code and now
have it working just fine. As well I learned a lot from suggestions and
trying different things about the timers and how they work.
By the end of the weekend I should have a working program...
Thanks again...
|
|
|
|
|
NO!!!!
There is no need for PictureBox.Refresh() or anything of that nature, by assigning a new image to the picturebox it knows it needs to repaint itself and it will.
And Application.DoEvents() is evil except maybe in the hands of experts; whenever your app seems to behave better with it, you probably have done it all wrong to begin with. Do not tell other people to use it!
|
|
|
|
|
hi, my senior told me to use DevShock dll in vb.net so i can easily do networking program.
but why everytime i search devshock.net in google, i keep finding thing like asp.net.
please help me, what should i type in google.. 
|
|
|
|
|
Why ask us; go and talk to your senior and ask him or her where to get it from and why you need it.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
he is already gone.
just had a fight with my manager.
i won't ask if i can do that. 
|
|
|
|
|
vkstarry wrote: he is already gone.
Then forget what he suggested and go your own way.
vkstarry wrote: just had a fight with my manager.
Life is hard.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
i'm not the one who fight with manager.
btw great answer, thank you 
|
|
|
|
|
Ah, I misunderstood your previous message.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
vkstarry wrote: btw great answer
I think you may have given me the wrong vote: 1=bad, 5=good.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
mostly fixed.
|
|
|
|
|
Thank you, your powers are awesome.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|