|
Your example shows the expected behavior. Since the cell doesn't have a value yet (DbNull,) one isn't selected in the ComboBox.
|
|
|
|
|
OK,
So how do I have the first item selected by default?
I have searched on the workaround since the dgvcmb doesn't have a selectedindex property but haven't found anything I have been able to use or haven't tried.
Thanks
|
|
|
|
|
The cell has to have a value that matches a Value in the data bound to the Combo.
In your example, the default cell value is DbNull, which the data in the Combo doesn't contain. Set the value of the cell to one of the values in the Combo and the combo will show the correct item.
|
|
|
|
|
try to solve the issue with the microsoft benchwork
regards,
Javed Ahmed Khan
|
|
|
|
|
HELLO
I HAVE PROGRAMMED A WINDOWS FORMS APPLICATION IN VB.NET AND TAPI
THE MAIN FORM OF THE APPLICATION IS HIDE AND EVERY TIME THE TELEPHONY RINGS THE FORM APEARS FOR 10 SECS
THE PROBLEMM IS THAT THE FORM ALWAYS ACTIVE OPENS
MAINFORM.SHOW() AND THE USER HAS TO REACTIVATE THE OTHER PROGRAMM OR FORM TO CONTINIUE HIS WORK
CAN SOMEBODY TELL ME HOW TO SHOW THE FORM WITHOUT TO MAKE IT ACTIVE
THANKS A LOT
KOSMAS
|
|
|
|
|
First, read the posting guidelines here[^], paying particular attention to point number 6. TYPING EVERYTHING IN UPPER CASE MEANS YOU'RE SCREAMING AT PEOPLE.
In order to show the form without activation, you'd have to call the Win32 API function ShowWindow . There's an example here[^].
|
|
|
|
|
I could not test it because i had no time but thanks a lot
kosmas
|
|
|
|
|
|
Was the Image that you're showing in the picturebox loaded from the very same file?? If so, you've run into a known issue where an Image object created using FromFile holds the original file open for the life of the Image object created from it. Read this[^] for a workaround.
|
|
|
|
|
The image was loaded into the picture box after reading it as binary file from the DataBase...
The link you had given is talking about when we open a file..
Which is different from what i am doing..
Here is what all i am doing...
- Connect to DB read the file
- Display it as image in picture box
- On click of a button open save file dialog and get the new destination file name and path
- save it as image on that path
Regards
Nishkarsh
|
|
|
|
|
OK, you didn't specify that in your original post.
There's a work around for this too. Basically, create your Image object from the data comming from the database, then create a NEW Image object using the first image as a source. Then you can use this copy anyway you like in your application and retain the ability to save to file.
Dim origBitmap As Bitmap ' This is the original image you created from the database
Dim copyBitmap As New Bitmap(origBitmap.Width, origBitmap.Height)
Dim g As Graphics = Graphics.FromImage(copyBitmap)
g.DrawImage(origBitmap, New Rectangle(0, 0, copyBitmap.Width, copyBitmap.Height), _
0, 0, origBitmap.Width, origBitmap.Height, GraphicsUnit.Pixel)
origBitmap.Dispose()
g.Dispose()
' The copy of the bitmap is in copyBitmap. This is the one you use in the rest of your code.
|
|
|
|
|
Thanks for the input
This is how exactly i am loading the file to the picture box
Dim ar(dataLength) As Byte<br />
<br />
myReader.GetBytes(0, 0, ar, 0, dataLength)<br />
myReader.Close()<br />
<br />
Dim b As New MemoryStream(ar)<br />
<br />
picView.Image = Image.FromStream(b)
How exactly can i implement ur suggestion
Another question
Can you please explain why can i NOT directly save the image when it is already ain the picture box in this case
Regards
Nishkarsh
|
|
|
|
|
Forget the picturebox. All it's there for is to show an image. You're not telling the picturebox to save anything. You're actually calling the Save method of the Image object that's been assigned to the Image property of the picturebox.
The reason has to do with GDI+ and it's annoying habit of locking source bits. You're getting the "general" error because the original source for the Image object no longer exists. Copying the bitmap you made gets around this little problem.
In your code, your creating a Bitmap object from a stream of bytes, but not really hanging onto that Bitmap anywhere in your code. All you have to do is change the code a bit:
Dim ar(dataLength) As Byte
myReader.GetBytes(0, 0, ar, 0, dataLength)
myReader.Close()
Dim b As New MemoryStream(ar)
Dim origBitmap As Bitmap = Image.FromStream(b)
... ' The rest of the code to copy the Bitmap goes here.
... ' Then you can tell the picturebox to show the image.
picView.Image = copyImage
|
|
|
|
|
Thanks a loot for helping me understand the issue... it worked
Regards
Nishkarsh
|
|
|
|
|
I am currently building a simple database access class. I have a function GetCourse which I want to get a course object from the database.
I could specify it like this:
<br />
public static function GetCourse(byval courseid as integer) as Course<br />
An alternative would be:
<br />
public static function GetCourse(byval courseid as integer, byref course as Course) as Boolean<br />
the two methods are only different by how they return the values. the first would return Nothing when it couldnt find a course (throw an exception or return Nothing when a database error occurred). the second function would return false when it couldnt find a course and true when it could (either throwing exceptions or returning false in the case of a db error) and it would assign the course details to the course parameter.
The calling method would either check for Nothing in the case of the first function or check for true/false in the case of the second function to indicate that the course could be found.
I would like to hear peoples opinions on which function you would prefer and why. Or if there is a better alternative
Thanks!
|
|
|
|
|
The first method is better. You have the option of either returning Nothing or throwing an exception. A custom exception would probably be ideal, depending on your requirements of course. Your calling code would just have to check to see if the return was Nothing instead of a Boolean.
|
|
|
|
|
Im not sure of your point. With the second method you also have the option of throwing an exception or returning false (instead of nothing).
the calling methods would be something like this (if the functions didnt handle their own exceptions
1.
<br />
try<br />
course = GetCourse(courseid)<br />
catch<br />
'error handle<br />
end try<br />
if course is nothing then<br />
' do something<br />
else<br />
'do something else<br />
end if<br />
2.
<br />
try<br />
if GetCourse(courseid, course) then<br />
' do something<br />
else<br />
' do something else<br />
end if<br />
catch<br />
' error handle<br />
end try<br />
theyre essentially the same as far as i can tell
|
|
|
|
|
Why use an extra Boolean that does that exact same thing as checking the return for an object?
|
|
|
|
|
If the first function handled all its exceptions internally it would return nothing when there was database error or there was no course with that ID in the database. The calling method wouldnt be able to tell what really happened. With the second function you could differentiate between when the function failed or whether there just wasnt a course with that id in the database. i dont think the calling method should care about how the function failed, just whether it did or not.
Allowing the functions to throw out exceptions in my opinion is a bad idea if you can just handle them internally.
Yes or no?
|
|
|
|
|
Kevin Brydon wrote: If the first function handled all its exceptions internally it would return nothing when there was database error or there was no course with that ID in the database. The calling method wouldnt be able to tell what really happened.
Yes, it would if the function was written to throw an exception and not bury them internally. Depending on the requirements, the function should throw an exception if there was a problem, and let the caller (business rules) decide what to do about it.
Kevin Brydon wrote: i dont think the calling method should care about how the function failed, just whether it did or not.
This is up to the business rules of your app, not you. Think about that. This is not a hard and fast rule in every application.
Kevin Brydon wrote: Allowing the functions to throw out exceptions in my opinion is a bad idea if you can just handle them internally.
There are many cases where the caller needs to know HOW the operation failed and handle the failure in ceratin ways depending on the type of failure. Just returning a True/False doesn't convery any kind of useful failure information back to the caller.
|
|
|
|
|
Sending parameters by reference should generally be avoided if practically possible. As the extra boolean is totally redundant in this case, the choise is rather simple.
Whether the method should return a null reference or throw an exception when it can not return an Course object, that depends on the reason. If it's normal for courses to be missing, it should return a null reference, but if the reason is that an error has occured, it should throw an exception.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: Whether the method should return a null reference or throw an exception when it can not return an Course object, that depends on the reason. If it's normal for courses to be missing, it should return a null reference, but if the reason is that an error has occured, it should throw an exception.
Another possibility which may ease things for the caller would be to have similar versions of the function, one of which will throw an exception if it can't retrieve a course for any reason, and one of which will simply return nothing in the case where it can tell that a course does not exist (it will still throw an exception in case of things like database error and so forth). An application could call the latter if it doesn't know whether the course exists, and the former when it knows that it should and will be in trouble if it doesn't. While returning 'nothing' would probably cause an exception in the latter case, having code throw a deliberate exception is probably better than causing a null-reference exception.
|
|
|
|
|
supercat9 wrote: Another possibility which may ease things for the caller would be to have similar versions of the function, one of which will throw an exception if it can't retrieve a course for any reason, and one of which will simply return nothing in the case where it can tell that a course does not exist (it will still throw an exception in case of things like database error and so forth).
More of a complement than an alternative... That could easily be accomplished with a method that gets a course and throws an exception if it's null:
Public Function GetCourseUnconditionally(courseId As Integer) As Course
Course result = GetCourse(courseId)
If result Is Nothing Then
Throw New AppplicationException("Course not found.");
End If
Return result
End Function
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for your answers. I've decided to get rid on my byref/boolean functions and opted for the first option. I think its the most sensible choice for my application and possibly is the best choice for most apps.
|
|
|
|
|
Hello,
I have a listview with a playlist, in column 0 are the names of the songs and column 1 is the parth/url of the song.
True a textbox i want to search for a song, column 0.
When i press for example ab, all songs beginning with ab must come to top of the listview, all other song under that.
Can anybody help me out with this???
Regards,
idi
|
|
|
|