C Style Casting In VB?

Aug 19, 2011

I have a object type variable (control .Tag) that I need to cast to a structured type, and change a member in. This is a contrived but representative example

[code]...

View 2 Replies


ADVERTISEMENT

Change The Native Scrollbar Style In Application To Custom Style?

Mar 23, 2011

how i can change the native scrollbar style in my application to my custom style. I can adopt a custom scrollbar to attain this purpose but this will not serve my purpose because i want this attribute in entire application. Like it the text in textbox gets longer than its bounds than the scrollbar appers are my custom bar not the formal ones

View 12 Replies

Datagridview.cell.style (back To Original Style)?

Apr 12, 2010

I set the cell style progromatically on a condition.. but when that condition is no longer met I want to go back to the grids.cell original (default) style property

if x=y then
row.Cells(column.Name.ToString).Style.ApplyStyle(mystyle)
else

[code].....

View 1 Replies

C# - A Style That Activates Depending On Another Style?

Dec 24, 2010

I am trying to make a style that only gets applied if the parent element of the element that the style refers to, has another specific style. Kind of like in CSS where you can do ".class1 .class2" to specify that the "class2" theme only applies if it is within an element with the class "class1". I do not wish to use any form of external DLLs or libraries for this task. I want to know if it's possible to implement on my own.

I've tried using MultiTriggers with no luck. I have a style that applies to all TextBlocks. I want the textblock to do the following: If the font-size of the textblock is 11 and the parent element's style is "PinnedSuggestion", set the foreground color to "#FF505050". If the font-size of the textblock is 11 and the parent element's style is "Suggestion", set the foreground color to "#FFCCCCCC". The conditions that I have tried to write to make this work, are as follows (the font-size condition is true, but the other one is not). The conditions are inside a style that applies to all textblocks in general.

[Code]...

View 1 Replies

Change The Button Style And Button Text Style On Mouse Rollover?

Mar 7, 2009

I am creating an application and am very new to VB. I have 4 buttons on my form which is like my applications main menu. I would like that each of the buttons behaves in the following way when there is a mouse rollover: The Button back color is changed from the default to Red The Button text is changed to Blue, Bold, and increases in font size I would also like all the buttons to go back to their initial state when the mouse leaves.

Another thing, instead of me writing code for each of the buttons event handlers (Mouse Hovers, and Mouse Leaves) is there a way I can write this code once, maybe as a function and then always call it for any button that I create from here on so that any new buttons take on this behaviour.

View 2 Replies

VS 2008 : Windows Is Running In XP Style Or In Windows Classic Style?

Feb 5, 2010

how to get the current Style of the Windows Xp programmatically. At the program startup I need to get if Windows is running in XP Style or in Windows Classic Style, so I will set my buttons Flatstyle property to flat or standard.

View 6 Replies

.net - Casting Interfaces And MEF?

Mar 13, 2009

I have the following problem with MEF: Interface definition to be used by host:

Public Interface IExecuteDoSomething
Inherits IAddinSettings
Event DataReceived As EventHandler(Of DataReceivedEventArgs)
Function DoSomething() As Boolean
End Interface

[Code]...

Everything seems to work fine until the Button2_Click routine is executed, then an InvalidCastException is thrown with the info:Unable to cast object of type 'System.Collections.Generic.List1[SharedLibrary.IExecuteDoSomething]' to type 'System.Collections.Generic.List1[SharedLibrary.IAddinSettings]'.

How can i solve this problem, because the imported object implements both of the interfaces?

View 1 Replies

.net - Difference Between Casting In C# And It

Dec 9, 2009

The next code works fine in C#:

[Code]...

But this code crash with a OverflowException in VB.Net.

[Code]...

Both codes seems the same to me. What is the difference and how can I get the C# code converted to VB.Net?

View 6 Replies

Casting Error?

Oct 16, 2009

get around this. I have a data base field that is a decimal data type and I want to display it in a text box with the following txtWeekdayRate = CType(RoomsDataRow!WeekdayRate, TextBox)I get the following error when I run my program.Unable to cast object of type 'System.Decimal' to type 'System.Windows.Forms.TextBox'.

View 20 Replies

Casting Value Must Be Less Than Infinity?

Mar 1, 2009

I am getting the followin error from my code. System.InvalidCastException was unhandled Message="Unable to cast object of type 'QADBASE.DMRDataLists' to type 'QADBASE.DMRData'." Source="QADBASE" I am getting the error in the code below on the createDMRIssue

[code]...

View 1 Replies

.net - Casting Generic Types?

Apr 20, 2010

Public Function CastToT(Of T)(ByVal GenericType(Of Object) data) As GenericType(Of T)Return DirectCast(data, GenericType(Of T))End Function

The above clearly does not work. Is there any way to perform this cast if I know that all objects inside data are in fact of Type T?

View 2 Replies

.net - Implemented Interface Needs Casting?

Jan 12, 2011

I have an Entity class which Implements IWeightable:

Public Interface IWeightable
Property WeightState As WeightState
End Interface

I have a WeightCalculator class:

Public Class WeightsCalculator
Public Sub New(...)
..
End Sub

Why can I not do wc.Calculate(entities)? I receive:

Unable to cast object of type
'System.Collections.Generic.List1[mynameSpace.Entity]'
to type
'System.Collections.Generic.IList1[myNamespace.IWeightable]'.

If Entity implements IWeightable why is this not possible?

View 2 Replies

C# - Casting String To Date

Mar 11, 2011

I am passing Date Field to SQL Database. Field is declared as String in the VB.Net Application. I wrote a piece of code for casting to Date

[Code]...

View 2 Replies

C# :: Casting In Visual Basic?

Apr 14, 2009

I'm a C# programmer who is forced to use VB (eh!!!!). I want to check multiple controls state in one method, in C# this would be accomplished like so:

if (((CheckBox)sender).Checked == true)
{
// Do something...

[code]...

View 4 Replies

Casting A Control To Another Page?

Apr 27, 2012

I have tried everything to no avail. I need to cast the value from a user selected dropdownlist to another dropdownlist on another page. The data in the textboxes are a series of numbers. Also is there a way to display the value in the second dropdown list as well as other values? For example, my dropdown has the values 1-6, user selects 4, which displays first in the dropdown on page 2 but the other values also display in case they want to change there selection??

If Not Page.PreviousPage Is Nothing Then
Dim table As Control = PreviousPage.Controls(0).FindControl("table1")
Dim ddl As DropDownList = CType(table.FindControl("ddlB_Codes"),c DropDownList)

[code].....

View 1 Replies

Casting After Obfuscation With Dotfuscator?

Mar 1, 2010

I'm trying to obfuscate some VB.NET 2003 app.The resulting assemblyes are obfuscated and "run" with some errors.I cleaned all potential reflection problems, but I'm not being able to read the selected value of a combobox.

I load the Combobox using their Datasource properties, using a collection of "VTPair" (a class created by me with 2 properties: one of string type and other of object type to store the value)

This combobox handle pairs like "Male | M" or "Female | F".When trying to see what is selected, I use if mycombo1.SelectedValue = "M" then.This code, after obfuscation, throws me an exception that cannot cast type "XX" to string "M".

So, I changed the code to something more correct, explicitly casting the selected value to String:

if ctype(mycombo1.SelectedValue,string) = "M" then But the error is the same.Debugin my original code, the SelectedValue property is of type "Object" but it is a string.I tried using the ComboBox.SelectedItem property that is also an object but this time what is inside is of type "VTPair" (my own class) and then trying to access its "Value" property (which is of type Object) and trying to cast to string fails again.

Does anyone have an idea to "translate" this piece of code to work OK after Dotfucate it?

View 2 Replies

Casting An Object Through An Interface (.NET 3.5)?

May 14, 2010

I have an object that inherits from an interface. I can create and return the following:

Dim o As IRequest
o = New Request
Return o

This works fine. Now I want to return a List(Of Requests), so I try the following:

Dim o As List(Of IRequest)
o = New List(Of Request)
Return o

The error below is being given on o = New List(Of Request)

System.Collections.Generic.List(Of MyObjects.Request)' cannot be converted to System.Collections.Generic.List(Of MyInterfaces.IRequest)'.Consider using 'System.Collections.Generic.IEnumerable(Of MyInterfaces.IRequest)'

View 2 Replies

Casting From X509 To X5092?

Nov 4, 2010

I don't know where it thinks I'm casting.

Here is my property

''' <summary>
''' Gets the GetX509Certificate from a file.
''' </summary>

[Code]....

and heres where it says im doing the illegal cast:

Dim cert As System.Security.Cryptography.X509Certificates.X509Certificate2 = Me.GetX509Certificate

Why is it saying that? Everything is defined in the right type but it still thinks I'm casting.

View 1 Replies

Casting Or Parsing Of Text?

Apr 20, 2012

in vb, you can use text which is in textbox instead of numerical expressions. I mean, if I write 50 in textbox1 and also I can write like that code:

Dim result As Double = TextBox1.Text + 0.4

as you see, I didnt convert any type but it works in vb.net

But I want to learn what are disadvantages of this using?

(I am just talking about arithmetic operations)

View 2 Replies

Casting To A Variable Type?

Jun 22, 2009

i have a property (items) that i want to use for either a checkedlistbox or a standard listbox depending on the value of another property.

heres the code i wrote that doesn't work:

[Code]...

View 5 Replies

Collections And Interfaces And Casting?

Nov 14, 2010

Say I have a interface called IProperties and I have a collection called colMyProperties that is a collection of IProperties. Then I have an object called clsProperty that implements the IProperty interface. Now, in my code where I add objects to the colMyProperties collection I add a bunch of clsProperty objects. so far so good.

Now when I try to access an object in the collection I can only access properties and methods of the IProperties interface, not the clsProperty object. What am I doing wrong? Do I need to cast the object?

View 2 Replies

DirectCast For Casting Without Conversion

Sep 4, 2009

I usually avoid VB's built-in conversion functions (CStr, CDate, CBool, CInt, etc.) unless I need to do an actual conversion. If I'm just casting, say from an object to a string, I normally use either DirectCast or TryCast, under the assumption that CStr, etc., are doing some extra stuff I don't need. But sometimes the DirectCast syntax is a little cumbersome, as in the following example.[code]SqlDataReader.Item returns an Object, which needs to be cast to a String. CStr is easier to read, type, and explain (IMO). My question is, does it matter which one I use? Should I just go with CStr (and CDate and CBool, etc.) and not worry about the extra work I assume those functions are doing? Is there any other downside to using these functions?

View 3 Replies

Instance Of Object Won't Go Away Even After Casting

Feb 28, 2012

i have the following code which walks through an Excel file and this works fine note that the following line does work well (folder is being set earlier in the code)

[Code]...

View 1 Replies

Performance - Fastest Casting In .NET?

May 14, 2009

When I have many controls on a Form (i.e. Label, Button etc) that do almost the same thing, I often use one method to handle all the controls Click, MouseDown, MouseUp events.But to know which of the controls throwing the event and access the properties of that control I need to cast the "sender" object to the correct type.

The thing is that I always know which type it is, I don't really have to "TryCast", "DirectCast" and check if the operation returns true. I some times use CType as well.

[Code]...

View 2 Replies

Proper Type Casting?

Jun 18, 2009

Delegate Sub UpdateTextHandler(ByVal recbuffpass() As Integer)

Private Sub someSub()
Dim f As frmMain = My.Application.OpenForms("frmMain")
f.Invoke(New UpdateTextHandler(AddressOf f.UpdateTextMethod), New Object() {recbuf})

[code].....

View 2 Replies

VS 2008 Casting An Object?

Sep 30, 2009

I've got a project called Service.Inside the project, i've got 2 windows classes.ClassA is the main windows class which opens up when I run the program.On ClassA, I've got a button which, when I click it, opens up ClassB which is the other windows class. Inside the button's eventhandler (click), I've got a string which contains the name of ClassB's class ie "ClassB". I will probably get this from a table. Is it possible to initiate the object ClassB without using if statments to check what the type of object is. In the code below, i've managed to create a o of type object, but i need to new it with the ClassB

vb.net Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

[Code]...

View 7 Replies

VS 2010 : Casting To An UInt16?

Aug 1, 2011

Apparently, this is not allowed? Is there a way to cast to an UInt16?

zero2 = CUInt16((Ch1OutputResults.range10Zero - 0) * 65535)

View 8 Replies

.net - CType And Type Casting Exception

Feb 25, 2011

[Code]...

What happens when a user wants to alocate "" as Item(DurationColumn) to integer? I get an exception. clean solution to avoid this and set 0 for ""?

View 5 Replies

.net - LINQ Casting With A Data.DataTableCollection?

Aug 18, 2010

I have the following VB.NET code that I am using to sort a Data.DataTable by column count.

For Each dtTarget As Data.DataTable In _
From x In Target.Tables _
Where DirectCast(x, Data.DataTable).Rows.Count > 0 _
Order By DirectCast(x, Data.DataTable).Columns.Count
...
Next

Is there a way to indicate that x is a Data.DataTable without having to DirectCast it each time it is referenced (twice in this case) in the LINQ query?

View 1 Replies

Casting - Bit Pack Int16 Into A Ushort .net?

Oct 22, 2009

I have to pack and unpack a 16bit Int from/into a Ushort in VB.net This is how I thought I could do it (doesn't work, gives me overflow exception)

'Pack Int16 into ushort '
Dim usPacked = CType(Data, UShort)
'unpack Int16 from ushort '
Dim unpacked = CType(data,Int16)

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved