|
Christian,
Thanks a lot for your help, the mud becomes ever clearer.
I was calling with as posted, I changed it as you suggested and it fires the method.
Of course I now get a new error, but hey no one said it would be easy.
Thanks again
Geoff
|
|
|
|
|
Hi all,
I am using Listview control in vb.net 2005, in that i am using a coloumn header in that. I wish to change the style(back color) of the coloumn header. I searched for it in the Properties, but i cant found it. Can any one suggest me how to change the Backcolor of the coloumn header.
It's little urgetn plz
Thankx in advance
Know is Drop, Unknown is Ocean
|
|
|
|
|
Hi,
I have created button controls dynamically and included contextmenu for that. When i right click on my dynamic control and choose the menu, How do I get that dynamic controls name?
Any luck.
Rams.
Be simple and Be sample.
|
|
|
|
|
hi, can any 1 suggest me the different kind of manipulations that can be done on an image in microsoft word using vb.net .I am working with VSTO 2005
sameer
|
|
|
|
|
I didn't think there were any.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I set out to write a Generic function that would find controls of a desired type and pass back an array of that type. For instance I could call the function and ask for all textbox's found on a form. However, I ran into a snag. I can test if a control is of Type T, but I have know way of converting that control to Type T. The following code shows the compromise I had to make due to this limitation.
'Returns a control array full of controls that match the desired type
Public Function ControlArray(Of T)(ByVal container As Control) As Control()
'Controls to pass back
Dim list As New List(Of Control)
For Each ctrl As Control In container.Controls
'If child control is of the desired type T then
'add to list
If ctrl.GetType Is GetType(T) Then list.Add(ctrl)
Next
'Return array
Return list.ToArray
End Function
Ideally this function would look something like the code below. The big difference is I want to return an array of type T. But how can I possibly convert a generic control to an unknown type?
Public Function ControlArray(Of T)(ByVal container As Control) As T()
'Controls to pass back
Dim list As New List(Of T)
For Each ctrl As Control In container.Controls
'If child control is of the desired type T then
'add to list
If ctrl.GetType Is GetType(T) Then
'The next statement won't compile and is the major problem I
'need to work around
list.Add(DirectCast(ctrl, T))
End If
Next
'Return array
Return list.ToArray
End Function
|
|
|
|
|
You need to constrain your generic statement. In C#, you'd do it like this
public List<T> ControArray<T>(Control container) where T : Control
Not sure of the VB syntax.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I tried converting the code with a converter I found online but the result didn't seem to be correct. However, I think I understand what you mean, but that's not the problem. Simply put I need to convert a control to it's real type. If I could figure that out I'd be all set. Any thoughts on that? At the moment I have figured out solution. I realized I can convert the control to an object and then add it to the list. As long as Option Strict isn't on this works just fine because it just uses implicit conversion. I'm okay with that for now but I'd still like to know if there is anyway to convert a generic control to it's actual type without knowing it's type a head of time. Here is the code I'm using right now, which is working just fine.
'Returns a control array full of controls that match the desired type
Shared Function ControlArray(Of T as control)(ByVal container As Control) As T()
'Controls to pass back
Dim list As New List(Of T)
For Each ctrl As Control In container.Controls
'If child control is of the desired type T then add to list
If ctrl.GetType Is GetType(T) Then list.Add(CType(ctrl, Object))
Next
'Return array
Return list.ToArray
End Function
-- modified at 20:53 Friday 26th January, 2007
Okay, I take it back what I said about the constraint not being a problem. Well, technically it wasn't a problem but now that I have added a constraint I am now able to add a control type to my list which is of T. Now I don't need to convert to an object first, however, an implicit conversion is still needed so Option Strict can't be turned on. Thanks for your help! It worked perfectly. If you have any ideas on making this option strict friendly please let me know.
|
|
|
|
|
Actually, the core problem is, you're iterating through a collection of controls, looking for objects that are of a more specific type. One solution that would work in C# is the 'as' keyword
foreach(Control ctrl in container.Controls)
{
T specific = ctrl as T;
if (specific != null)
{
list.Add(specific);
}
}
This code makes use of the 'as' keyword, which does a conversion, or returns null if one is not possible. This removes the need for a cast, and replaces the code you've got using GetType ( which is not BAD code, but this approach changes the code rather than adds to it ).
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Thanks once again for your help. I converted your code and 'as' converted to CType(ctrl, T) which I am familiar with. However, it seems that unlike C# a failed conversion will generate an error. I could do something similiar to your code by using TryCast instead which does return nothing if it fails. I'm not exactly sure what the technical differences are between CType and TryCast (aside from no errors that is). I think I might have to look that up. Now that I have used a constraint, CType and TryCast/Directcast work. Before I used a constraint they would not compile. It seems the constraint was all I needed and allows me to convert a control type to T. Now that I don't need to rely on a implicit conversion Option Strict is happy
|
|
|
|
|
CType is not the same, nor is DirectCast. TryCast is the same as the 'as' keyword.
Sounds like you've got it working, anyhow
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I'm using a ReportViewer object to display a local report in a windows forms project. When I run the program on my own machine everything works fine. (Windows 2000) When I run it on a virtual machine using Windows XP the report begins to load, then the screen displays this error message: "Report processing has been cancelled" and then a second or two later the report loads just fine. I've searched and found a few other people who have had this problem on other forums, but no one has posted a solution or workaround. I don't know if Windows 2000 vs XP is the problem or what. Does anyone have any ideas why this is error is showing and how I can fix it or hide the message?
Also...when I run it in debug OR Release mode with Visual Studio 2005, instead of seeing the "Report processing has been cancelled" message I get a nice little graphic and a message that says "Report is being Generated". Why does this work correctly through visual studio by not when I run the .exe by itself?
|
|
|
|
|
Someone was able to help me out with this issue on another forum, so I thought I'd post it for anyone else having similar troubles.
The following lines will cause the cancel message:
Me.ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout)<br />
Me.ReportViewer1.ZoomMode = ZoomMode.PageWidth
If you put these lines in the Rendering_Complete, no cancel message will appear. But if you put those lines in the load event, you will get the message.
|
|
|
|
|
Hello Folks,
I am trying to overide my .net 2.0 DataGridView using VB 2005
I have a gird of 10x10 thus I have hundred cells in that grid. But for each cell I want to save three values. I have override my Treeview to save three values but cannot do the same for DataGridView component. Any Hints please
What happening is
Public Class myDataGridThing
Inherits DataGridView
End Class
|
|
|
|
|
Instead of doing this, you can just create a struct that contains your three values and make an array of this struct your data source, then set up the grid to render it however you like.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Thank you Christian,
Yes that can be one of the way. But I am not too experienced with it.
There is a object called DataGridViewCell which can be inherited to create my own myCustomGridViewCell
But the thing is how can I tell the DataGridView to use myCustomGridViewCell instead of default DataGridViewCell. I know there is a way but trying to figure out. This will be easiest way of saving as many differect values as possible in one cell. And you can easily Set or Get them by:
DataGridView1.item(0,0).myValue1 = "This is first Custom Value"
DataGridView1.item(0,0).myValue2 = "This is Second Custom Value"
DataGridView1.item(0,0).myValue3 = "This is third Custom Value"
I can create myCustomGridViewCell by creating a Public Class (as shown below)
Public Class myCustomGridViewCell
Inherits DataGridViewCell
Public myValue1 As String
Public myValue2 As String
Public myValue3 As String
End Class
The problem is how can I tell the DataGridView to use myCustomGridViewCell
There will be a way to override the DataGridView1 class to define my custom obects.
|
|
|
|
|
Hi I'm trying to get the datagridview cell value into listcontrol.
The reason why I importing datagridview data into listcontrol is to be able to change the header fields name.
I tried to find the way to right click on mouse and edit/rename the datagridview headercell name.
For example,
"No" "date" "address" header to "Number" "Date" "Address".
I want to be able to edit the header string when the user click on Right button on mouse or double click on mouse, Like we can edit table header name by double clicking in Microsoft Access.
I couldnt' find any example to do so. I guess datagridview doesnt' allow to edit the header name.
So I decided to use the listview control to do the same action.
So How can I make it so the header is editable when the user click on right click or double??
Thanks.
|
|
|
|
|
Ok. Here is my scenarion I have a file that I need to load some line to a grid, but
I'm have diffulties doing do. The following is the structure of my file.
0 62.5 0 0 62.5 0 0 62.5 0 0 'H2O'
0 115 461.5 461.5 115 461.5 461.5 115 461.5 461.5 'CH'
0 90 76.9 76.9 95 107.7 107.7 90 76.9 76.9 'CH'
0 97 76.9 76.9 97 107.7 107.7 97 76.9 76.9 'CH'
0 97 76.9 76.9 100 153.8 153.8 97 76.9 76.9 'CH'
I need to assign each number to a variable to load into my grid.
Help please.
|
|
|
|
|
The System.IO namespace has the classes you need to read files. I think that My gives you a shortcut as well. System.IO.File.ReadAllLines will read your file into a string array, a string per line. You can then call the Split method on the string class to turn each line into a string array ( split on space ). Then double.TryParse can be used to find all the numbers, and you'll always know that the last element is a string, so treat that accordingly.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
my be you should try file manipulation..
ex:
While yourFileHandler.Peek <> -1
yourArray = split(yourFileHandler.Readline()," ")
For i as Integer =0 to Ubound(yourArray)
'yourArray(i) do assigning the value of array here into your datagrid
Next
End While
|
|
|
|
|
Here is some bits of code (not complete) I have used to do somthing similar.
1) it opens the launch.ini file
2) creates a streamreader and puts the content of the file into infile
3) then it reads infile one char at a time building a temp string until it reads a comma (in your case it would be a space)
4) On reaching a comma it stores the value in a string (in the example IP and Mac)
Hope this helps you get started.
thefile = "c:\launch.ini"
Try
fs = New FileStream(thefile, FileMode.Open)
Catch excep As System.IO.FileNotFoundException
Exit Sub
End Try
Dim sr As StreamReader = New StreamReader(fs)
Dim infile As String ' String used to accept file input
Dim c As Char
Dim count As Integer
Dim temp As String
infile = sr.ReadToEnd
sr.Close()
fs.Close()
'MessageBox.Show(infile)
count = 0
Do
c = infile.Substring(count, 1)
count = count + 1
If c <> "," Then temp &= c
Loop While c <> ","
ip = temp
ipbox.Text = ip
temp = ""
Do
c = infile.Substring(count, 1)
count = count + 1
If c <> "," Then temp &= c
Loop While c <> ","
mac = temp
macbox.Text = mac
temp = ""
|
|
|
|
|
|
Can anyone tell what is the vb.net code for displaying an image using microsoft office document imaging viewer control 11 and how to zoom in or out of an image.
It would be something like the following
picImage.Image = New Bitmap("c:\test.tif")
or to zoom picImage.zoom = 50
|
|
|
|
|
Please don't make your project rely on office, merely to show a bitmap.
Handle your Paint event. In there, draw the bitmap, using the Graphics object in the event args, and the DrawImage method. The Graphics object also has a ScaleTransform method, you can call this to change the zoom of your bitmap, or you can manipulate the parameters to DrawImage to do it.
It's pretty straightforward.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Thanks everyone for all their help.
I have done the following code and it works. Hopefully this will be useful to others. All you need on your form is a Panel, Picture Box (this goes inside panel) and a button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
picImage.Image = New Bitmap("c:\test.tif")
' Get the source bitmap.
Dim bmSource As New Bitmap(picImage.Image)
' Make a bitmap for the result.
Dim bmDestination As New Bitmap(
CInt(bmSource .Width / 8), _
CInt(bmSource .Height / 8))
' Make a Graphics object
Dim grDest As Graphics = Graphics.FromImage(bmDestination)
' Copy the source image into the destination bitmap.
grDest.DrawImage(bmSource, 0, 0, _
bmDestination.Width + 1, _
bmDestination.Height + 1)
' Display the result.
picDest.Image = bmDestination
End Sub
|
|
|
|