Click here to Skip to main content
15,890,717 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: How I can see a message when my Caps-Button is active? Pin
Dave Kreskowiak22-Jan-06 4:30
mveDave Kreskowiak22-Jan-06 4:30 
GeneralRe: How I can see a message when my Caps-Button is active? Pin
kostasdiktia222-Jan-06 9:03
kostasdiktia222-Jan-06 9:03 
GeneralRe: How I can see a message when my Caps-Button is active? Pin
Dave Kreskowiak22-Jan-06 9:39
mveDave Kreskowiak22-Jan-06 9:39 
GeneralRe: How I can see a message when my Caps-Button is active? Pin
kostasdiktia223-Jan-06 12:56
kostasdiktia223-Jan-06 12:56 
QuestionImage Capture Pin
Shonan21-Jan-06 21:26
Shonan21-Jan-06 21:26 
AnswerRe: Image Capture Pin
Dave Kreskowiak22-Jan-06 4:27
mveDave Kreskowiak22-Jan-06 4:27 
QuestionCrystal Report -- TotalPageCount Pin
Madni Abbasi21-Jan-06 20:17
Madni Abbasi21-Jan-06 20:17 
QuestionProblem using custom DataGridColumnStyles with DataGridTableStyle Pin
nzmike21-Jan-06 15:10
nzmike21-Jan-06 15:10 
I have a user control which includes a Datagrid that needs one column for each hour of the day for five categories... so my datagrid would have 5 rows and 25 columns. The 1st column is the category name and is no problem. Columns 2-25 store the hourly figures and what I want to do is use a custom DataGridColumnStyle on these but when I try to cast the DataGridTaleStyles.GridColumnStyles for each of these columns to my custom DataGridColumnStyle it gives me an invalid cast error.

Since that's probably as clear as mud here's the code I have:

Public Class vbsDataGridTextBoxColumn
Inherits System.Windows.Forms.DataGridTextBoxColumn

Public Sub New()

'This is just to get it working - we'll set more properties later.
Me.Alignment = HorizontalAlignment.Right
Me.TextBox.MaxLength = 6
Me.Width = 50

End Sub

End Class

That's the custom Column Style (we'll set more properties later)... and here is the method that runs in the user control to change column types on the fly as the DataGrid is populated. (We need to do this as the DataGrid can switch from being editable or not depending on which day's data is being edited) I've commented the line in red that throws the exception.

Private Sub vbsDataGrid_DataSourceChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles vbsDataGrid.DataSourceChanged

Dim i As Int32 = 0

Dim cm As CurrencyManager = Me.BindingContext(Me.vbsDataGrid.DataSource)
Dim ts As New DataGridTableStyle
ts.MappingName = DirectCast(cm.List, DataView).Table.TableName

'Make the dataGrid use our new tablestyle and bind it to our table
Me.vbsDataGrid.TableStyles.Clear()
Me.vbsDataGrid.TableStyles.Add(ts)

'Now create a ColumnStyle for each of the hourly figure columns (1-24) in the datagrid using our custom class. Note the first column (0) doesn't need a custom style.

Dim tbc As New vbsDataGridTextBoxColumn

For i = 1 To 24
'***THIS IS WHERE I GET AN INVALID CAST ERROR***
tbc = CType(ts.GridColumnStyles(i), vbsDataGridTextBoxColumn)

tbc.HeaderText = "Hour " & i.ToString()
Next
End If
End Sub


Anyone know why this would happen? If I create 'tbc' as a normal DataGridTextBoxColumn the cast has no problem - it's only when I use my custom DataGridTextBoxColumn class I get the error.

Hope someone can help - I'm darned if I know what's going on!

Mike





AnswerRe: Problem using custom DataGridColumnStyles with DataGridTableStyle Pin
Dave Kreskowiak22-Jan-06 4:26
mveDave Kreskowiak22-Jan-06 4:26 
GeneralRe: Problem using custom DataGridColumnStyles with DataGridTableStyle Pin
nzmike22-Jan-06 19:44
nzmike22-Jan-06 19:44 
GeneralRe: Problem using custom DataGridColumnStyles with DataGridTableStyle Pin
Dave Kreskowiak23-Jan-06 1:49
mveDave Kreskowiak23-Jan-06 1:49 
QuestionShortcut Pin
militiaware21-Jan-06 12:23
militiaware21-Jan-06 12:23 
AnswerRe: Shortcut Pin
Dave Kreskowiak21-Jan-06 17:57
mveDave Kreskowiak21-Jan-06 17:57 
AnswerRe: Shortcut Pin
kostasdiktia221-Jan-06 21:14
kostasdiktia221-Jan-06 21:14 
QuestionIP Address Pin
militiaware21-Jan-06 12:12
militiaware21-Jan-06 12:12 
AnswerRe: IP Address Pin
Dave Kreskowiak21-Jan-06 17:53
mveDave Kreskowiak21-Jan-06 17:53 
QuestionCreating an event at runtime Pin
Mark0621-Jan-06 2:27
Mark0621-Jan-06 2:27 
AnswerRe: Creating an event at runtime Pin
Guffa21-Jan-06 2:54
Guffa21-Jan-06 2:54 
GeneralRe: Creating an event at runtime Pin
Mark0621-Jan-06 3:19
Mark0621-Jan-06 3:19 
GeneralRe: Creating an event at runtime Pin
Dave Kreskowiak21-Jan-06 4:31
mveDave Kreskowiak21-Jan-06 4:31 
QuestionHelp with calculator Pin
lonewolfa120-Jan-06 17:47
lonewolfa120-Jan-06 17:47 
QuestionHow I can change the values in cells of an EXISTING .xls file? Visual Basic .NET Pin
kostasdiktia220-Jan-06 17:39
kostasdiktia220-Jan-06 17:39 
AnswerRe: How I can change the values in cells of an EXISTING .xls file? Visual Basic .NET Pin
Dave Kreskowiak21-Jan-06 4:28
mveDave Kreskowiak21-Jan-06 4:28 
AnswerRe: How I can change the values in cells of an EXISTING .xls file? Visual Basic .NET Pin
Mekong River21-Jan-06 4:38
Mekong River21-Jan-06 4:38 
AnswerLike this? Pin
kostasdiktia221-Jan-06 4:50
kostasdiktia221-Jan-06 4:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.