|
|
Hi,
I'm using datagridview in C# windows application and i have four datagridtextboxcolumn at designtime and my fifth column is datagridcomboboxcolumn which is added at run time. I want to pass some value ( number) as input to combo at run time, so that values in the combo are different for each row in the grid. I want to pass some number to the fifth combobox column so that combobox populates different values for each row in the grid. This is my scenario, can anyone help me with this with detailed explanation and C# code.
|
|
|
|
|
You might want to try the C# forum? You will probably get a more pertinent explanation than in this (VB) forum.
|
|
|
|
|
1. Wrong forum
2. You can bind the column and set the value member as desired.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
|
|
|
|
|
This is the code that calls the form where the file is displayed in a picture box.
<br />
frmCEA.ContactID = intContactID<br />
frmCEA.Text = "Edit a contact"<br />
frmCEA.ShowDialog()<br />
strAvatarToDelete = frmCEA.AvatarForDeletion<br />
frmCEA.Close()<br />
frmCEA.Dispose()<br />
<br />
If strAvatarToDelete.Trim > "" Then<br />
My.Computer.FileSystem.DeleteFile(strAvatarToDelete)<br />
End If<br />
I have tried on the form, and off the form like this, to delete an avatar but every time I get this message - even if I want to change photos.
The process cannot access the file 'C:\Documents and Settings\All Users\Application Data\.....\Avatars\AV000001' because it is being used by another process.
Any out there know why this might be??
|
|
|
|
|
Are there any other methods in your app using the file? If so, you need to cleanly end those resources so that the file is unlocked.
make sure the file is not readonly. Make sure you don't have other apps using the file.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Thanks for responding.
No nothing else is using the file. It just gets placed in the picture box:
Try
Me.PictureBox1.BackgroundImage = GetAvatar(ContactID)
Me.cmdDeleteImage.Enabled = True
Catch ex As Exception
Me.cmdDeleteImage.Enabled = False
End Try
Where GetAvatar =
Friend Function GetAvatar(ByVal ContactID As Integer) As Drawing.Image
Dim pict As Drawing.Image
'This just collects a file name
Dim strFilename As String = cDBHandler.ExtractContactImage(ContactID)
Try
If strFilename.Trim > "" Then
pict = Drawing.Image.FromFile(strFileName)
Else
pict = My.Resources.nouserpic_grey
End If
Catch ex As Exception
pict = My.Resources.nouserpic_grey
End Try
Return pict
End Function
Might it be because it ic alled in from another routine??
|
|
|
|
|
Well, if you rem out the logic in GetAvatar and loading it into the picture box, can you delete the file?
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Thanks for the suggestion Jon_Boy but unfortunately that would impact my code. I will give it a go if all else fails however.
|
|
|
|
|
Wasn't suggesting that as a perm. fix - just as a way for you now and in the future easily determine if and where your code was locking a file.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
TheComputerMan wrote: pict = Drawing.Image.FromFile(strFileName)
This locks the file. You need instead to create a new bitmap. open the file, copy the bitmap, and delete the original. At least, that's how I've got around this bug in GDI+ in the past.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I tried that Christian (using pict2 = pict.clone and then disposing pict) but still the same problem. It obviously carries the info accross to the clone.
Friend Function GetAvatar(ByVal ContactID As Integer) As Drawing.Bitmap
Dim pict As Drawing.Bitmap
Dim pict2 As Drawing.Bitmap
'This just gets the file name
Dim strFilename As String = cDBHandler.ExtractContactImage(ContactID)
Try
If strFilename.Trim > "" Then
pict = Drawing.Bitmap.FromFile(strFilename)
pict2 = pict.Clone()
pict.Dispose()
Else
pict2 = My.Resources.nouserpic_grey
End If
Catch ex As Exception
pict2 = My.Resources.nouserpic_grey
End Try
Return pict2
End Function
Looks like I might have to try storing the pic in the database, but I did not want to do that as it is only an SQL Server 2005 Compact so space limited.
Thanks anyway! (If you can think of any other way I would like to hear from you)
|
|
|
|
|
TheComputerMan wrote: pict2 = pict.Clone()
Christian is right, but you did not take his advise.
TheComputerMan wrote: Bitmap.FromFile(strFilename)
This is what keeps your file locked. Hence make and use a copy of the IMAGE and dispose of the original right away.
TheComputerMan wrote: any other way
No need. The one way is fine if executed properly.
|
|
|
|
|
This has been widely documented since the early days of .NET 1.0. The problem is you loaded the image file directly into an Image object in the PictureBox control. The Image object keeps the file locked for it's entire lifetime.
The solution is to load the image using a FileStream, then pass the resulting stream to the construcotr of a new Bitmap object, then close the stream, and assign the Bitmap object to the Image property of the PictureBox.
|
|
|
|
|
Thanks Dave. I think I know how to do that so I will give that a go.
|
|
|
|
|
|
Why do you need picbyteArray variable?! You're not using it...
|
|
|
|
|
Hi Fabio,
Thanks for that. I had pulled the code from another program where I am using it to store the picture in SQL Server and forgot to take that bit out! Duh!!
The corrected code block is:
Friend Function GetAvatar(ByVal ContactID As Integer) As Drawing.Bitmap
Dim pict As Drawing.Bitmap
'This just gets the file name
Dim strFilename As String = cDBHandler.ExtractContactImage(ContactID)
Try
If strFilename.Trim > "" Then
Dim fs As New System.IO.FileStream(strFilename, IO.FileMode.Open, IO.FileAccess.Read)
pict = Drawing.Bitmap.FromStream(fs)
fs.Close()
Else
pict = My.Resources.nouserpic_grey
End If
Catch ex As Exception
pict = My.Resources.nouserpic_grey
End Try
Return pict
End Function
Sorry if that caused any confusion to anyone.
|
|
|
|
|
have a form that adds a new date to a sql database. What i want to do is when the user clicks add a new day, it comes up with a text box to add a new day. When the user tabs to the first feild, i want the lost focus to check the combo box to see if the date is already in the list?
Private Sub txtFields_LostFocus(Index As Integer)
Dim ifeild As Integer
Dim flddate As String
flddate = frmCashSheet.cmbDate.Text
ifeild = Index
If ifeild = 0 Then
frmCashSheet.txtFields.Item(0).Text = flddate
MsgBox "date has been entered already, Please select a new date"
frmCashSheet.txtFields(0).SetFocus
Else
For Inner = 0 To 32
txtFields(ifeild).BackColor = &HFF&
Next Inner
calculate
End If
End Sub
|
|
|
|
|
<quote>Private Sub txtFields_LostFocus(Index As Integer)
This does not appear to be called from anywhere by a handler and has the wrong parameters.
Private Sub txtFields_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFields.LostFocus
Index would have to come from reading something but I am not sure what from this example.
|
|
|
|
|
It is correct is he's using VB6.
|
|
|
|
|
Oops! Sorry did not twig that.
|
|
|
|
|
So, where's the code that goes through each item in the ComboBox items and compares the two??
|
|
|
|
|
School Library System Software RUN-TIME error 713
plas soly
pranav trivedi
|
|
|
|
|