|
Which DataGrid are you talking about? WinForms or ASP.NET? Which version of .NET are you using?
Are you prepared to write a TON of code to implement this and the custom rendering you're going to have to do for each column type?
|
|
|
|
|
Hi Dave,
sorry for late reply
Actually iam new to vb.net.
and my requirement is to create a new property ie.BorderColor property at cell level.
i implemented it using CellPainting but here it is not at cell level iam writing properties at grid level and amiipulating it.
But now it is working fine some times But i will it is not the appropriate way as it will paint the entire grid every time(becoz if grid contains huge data then there will lots of performance issues).
So i thought of creating a new property at cell level called "BorderColor Property"
thid datagrid is in windows application(winforms not asp.net,iam trying it out in vs2005 and .netframework 2.0.But actually i should do it in vs2008 and .netframework 3.5)
So please guide me how to achieve it.
and i feel we can create this property becoz,we already have a property called borderstyle propety at cell level.So y can't we create a new property in custom grid
|
|
|
|
|
OK, if you're using .NET 2.0, why are you using the old DataGrid and not the DataGridView?
rasnarakesh wrote: we already have a property called borderstyle propety at cell level
This tells me that you're using the DataGridView control, not the old DataGrid. Yes, there is a huge difference in how they work.
In either case, the problem you have is that each column renders its cells, not the row or the grid. Since each column knows how to render it's own data type (TextBox, ComboBox, ...) you have to create a new DataGridViewColumn class for each of those column styles you're using. You cannot change which class those columns inherit from, so you now have to create your own versions of them, add this property and the required drawing code.
You can read more about this here[^]. It's a pretty involved process...
|
|
|
|
|
Thanks for quick reply dave
But instead of overriding datagridviewcolumn class there is no other go
i have tried inheriting datagridviewcolumn class but that is not the way that we require.
We require it as a new property.
now i created property at grid level but i am unable to create at cell level
this custom grid that we are going create is used by others who may not know all these details.
So it should function similar to other properties at cell level
Is that not possible??
Thanks
Rasna
|
|
|
|
|
And dave the Link that you gave is laeding me google page
|
|
|
|
|
Dave was trying to politely suggest that you search the internet for a solution rather than asking here as it is pretty certain that someone has already done something similar.
If you had, you might have found Use Event to Set Row/Cell BackColor in Custom DataGridView[^] here on Code Project. Search in the article for 'border' and you will find what you are looking for.
You can also do this sort of thing by simply handling the CellPainting event of the DataGridView
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
Hi Henry,
Thank you very much for the link it's really useful in one way
But still my issue is not resolved.Here there is no choice for user to select the color in the properties window.Approach you mentioned is at runtime but i need it at design time
But really thank you henry it helps a lot.
But still can you guide me in the way that i need???
Thanks
Rasna
|
|
|
|
|
There are only two ways that I can think of to do what you require.
1). Regrettably for you, it means creating a custom (I am assuming that the cell type is TextBox) DataGridViewTextBoxCell and DataGridViewTextBoxColumn and simply adding a BorderColor property then overriding the PaintBorder or Paint methods to use this new property.
2). Create a custom DataGridView add the BorderColor as above (probably better called 'CellBorderColor' since we are subclassing the whole grid) and overriding the OnCellPainting eventhandler to use the color property.
Sorry not to be of more help.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
|
|
|
|
|
Sorry henry,
I tried your 2 ways but the performance is very slow that to painting at cell by level cannot be done if cellpainting event is used beceause if boder color for two or three cell is selected at runtime then cell painting event ovverides other two colors and paint only the last color.So for this i used arrays and tried but the performance is too slow not only that it is not working properly if scrool bar is there .
I may be missing some thing please correct me if iam wrong anywhere.
I will post the code that i have did
Imports System.ComponentModel
Imports System.Windows.Forms
Public Class gridcustom
Inherits System.Windows.Forms.DataGridView
Private mOldColor As Color ' Original button color
Private mMOColor As Color ' Mouse Over color
Private selBorderColor As Color ' Mouse Over color
Private cellwidth As Single ' Original button color
Private Selcellwidth As Single ' Original button color
'Private RowValue As Integer() ' Original button color
'Private ColValue As Integer() ' Original button color
' Dim i, j As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim Colrcount As Integer
Dim Cellscount As Integer
Dim a(0, 0) As TwoDColor
Dim b(0, 0) As TwoDCell
Dim selcolorcountarray As New ArrayList()
Dim selWidthcarray As New ArrayList()
Dim SelRowcountarray As New ArrayList()
Dim selcolcountarray As New ArrayList()
Dim selcolorcount(100) As Color
Dim Widthcount(100) As Single
Dim SelRowcount(100) As Integer
Dim selcolcount(100) As Integer
Private RowValue As Integer ' Original button color
Private ColValue As Integer ' Original button color
' <System.ComponentModel.Category("Appearance")> _
Property BorderColorForAllcells() As Color
Get
BorderColorForAllcells = mMOColor
End Get
Set(ByVal Value As Color)
mMOColor = Value
End Set
End Property
Property BorderWidthForAllcells() As Single
Get
BorderWidthForAllcells = cellwidth
End Get
Set(ByVal Value As Single)
cellwidth = Value
End Set
End Property
Property BorderColorSelectedcells() As Color
Get
BorderColorSelectedcells = selBorderColor
End Get
Set(ByVal Value As Color)
selBorderColor = Value
End Set
End Property
Property BorderWidthForSelectedcells() As Single
Get
BorderWidthForSelectedcells = Selcellwidth
End Get
Set(ByVal Value As Single)
Selcellwidth = Value
selWidthcarray.Add(Selcellwidth)
End Set
End Property
Property RowValueSelectedcells() As Integer
Get
RowValueSelectedcells = RowValue
End Get
Set(ByVal Value As Integer)
RowValue = Value
SelRowcountarray.Add(RowValue)
End Set
End Property
Property ColumnValueSelectedcells() As Integer
Get
ColumnValueSelectedcells = ColValue
End Get
Set(ByVal Value As Integer)
ColValue = Value
selcolcountarray.Add(ColValue)
End Set
End Property
Private Sub dataGridView1_CellPainting(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles MyBase.CellPainting
If ((e.State And DataGridViewElementStates.Selected) = DataGridViewElementStates.Selected) Then
Return
End If
If e.ColumnIndex >= 0 AndAlso e.RowIndex >= 0 Then
DRAWCELL(mMOColor, e.RowIndex, e.ColumnIndex, cellwidth, e)
End If
If (selcolorcountarray.Count >= 1) Then
If (selcolorcountarray.Item(0) = (Color.Empty) And selcolcountarray.Item(0) = 0 And SelRowcountarray.Item(0) = 0) Then
selcolorcountarray.RemoveAt(0)
selcolcountarray.RemoveAt(0)
SelRowcountarray.RemoveAt(0)
End If
If (selcolorcountarray.Count >= 1 And k < selcolorcountarray.Count) Then
'If (selcolorcountarray.Item(0)<> color.Empty ) Then
If e.ColumnIndex = CType(selcolcountarray.Item(k), Integer) AndAlso e.RowIndex = CType(SelRowcountarray.Item(k), Integer) Then
If (selWidthcarray.Count <= k) Then
selWidthcarray.Add(0.0)
End If
DRAWCELL(selcolorcountarray.Item(k), e.RowIndex, e.ColumnIndex, selWidthcarray.Item(k), e)
k = k + 1
If (k = selcolorcountarray.Count) Then
k = 0
End If
End If
End If
End If
End Sub
Private Sub DRAWCELL(ByVal c As Color, ByVal row As Integer, ByVal col As Integer, ByVal width As Single, ByVal e As DataGridViewCellPaintingEventArgs)
Dim newRect As New Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, _
e.CellBounds.Width - 4, e.CellBounds.Height - 4)
Dim backColorBrush As New SolidBrush(e.CellStyle.BackColor)
Dim ForeColorBrush As New SolidBrush(e.CellStyle.ForeColor)
Dim gridBrush As New SolidBrush(Me.GridColor)
Dim gridLinePen As New Pen(gridBrush)
Dim color As New System.Drawing.Pen(c, width)
Try
' Erase the cell.
e.Graphics.FillRectangle(backColorBrush, e.CellBounds)
' Draw the grid lines (only the right and bottom lines;
' DataGridView takes care of the others).
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, _
e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, _
e.CellBounds.Bottom - 1)
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, _
e.CellBounds.Top, e.CellBounds.Right - 1, _
e.CellBounds.Bottom)
' Draw the inset highlight box.
e.Graphics.DrawRectangle(color, newRect)
'' Draw the text content of the cell, ignoring alignment.
If (e.Value IsNot Nothing) Then
e.Graphics.DrawString(CStr(e.Value), e.CellStyle.Font, _
ForeColorBrush, e.CellBounds.X + 2, e.CellBounds.Y + 2, _
StringFormat.GenericDefault)
End If
' e.PaintContent(e.CellBounds)
e.Handled = True
Finally
gridLinePen.Dispose()
gridBrush.Dispose()
backColorBrush.Dispose()
End Try
End Sub
End Class
End Sub
End Class
Code in form class
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("column1", GetType(Integer)))
dt.Columns.Add(New DataColumn("column2", GetType(String)))
dt.Columns.Add(New DataColumn("column3", GetType(String)))
dt.Columns.Add(New DataColumn("column4", GetType(String)))
dt.Columns.Add(New DataColumn("column5", GetType(String)))
Dim i As Integer
For i = 0 To 10
Dim dr As DataRow = dt.NewRow()
dr("column1") = i
dr("column2") = "item" & i.ToString()
dr("column3") = "item" & i.ToString()
dr("column4") = "item" & i.ToString()
dr("column5") = "item" & i.ToString()
dt.Rows.Add(dr)
Next
Me.Gridcustom1.DataSource = dt
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim intcount As Integer = 0
For Each Row As DataGridViewRow In Gridcustom1.Rows
If Gridcustom1.Rows(intcount).Cells(1).Value = "item0" Then
Me.Gridcustom1.ColumnValueSelectedcells = 1
Me.Gridcustom1.RowValueSelectedcells = intcount
Me.Gridcustom1.BorderColorSelectedcells = Color.Chocolate
'Me.Gridcustom1.Rows(intcount).DefaultCellStyle.BackColor = Color.Aqua
End If
If Gridcustom1.Rows(intcount).Cells(1).Value = "item1" Then
Me.Gridcustom1.ColumnValueSelectedcells = 1
Me.Gridcustom1.RowValueSelectedcells = intcount
Me.Gridcustom1.BorderColorSelectedcells = Color.DarkBlue
End If
If Gridcustom1.Rows(intcount).Cells(0).Value = "4" Then
Me.Gridcustom1.ColumnValueSelectedcells = 0
Me.Gridcustom1.RowValueSelectedcells = intcount
Me.Gridcustom1.BorderColorSelectedcells = Color.Green
End If
intcount += 1
Next Row
End Sub
Please correct me if iam wrong.
Thanks
Rasagna
|
|
|
|
|
Hi All
I am really struggeling with DateTime Formats.
I have an incoming table of data coming in.It is constantly busy.
I am writing a monitor system on this table.So what I want to do is retrieve the last entries dateTime.
SELECT TOP(1) DateTime FROM TABLE
ORDER BY DateTime DESC.
What I want to know is:
How do I determine if the DateTime I received is older than 1 Hour from DateTime.Now
AND Ex
How do I determine if the DateTime I received is older than 5 Minutes from DateTime.Now
OR EX
How do I determine if the DateTime I received is older than 1Hour.5 Minutes from DateTime.Now
Thanks a million in advanced
|
|
|
|
|
|
it is not clear whether you want an SQL or a VB.NET approach.
Maybe this article[^] gets you going.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Its very simple
Use DateDiff Function
First Argument is the Difference Interval
See the DateInterval enumeration(has hours, seconds etc.)
The Second Argument is the date you retrieve
The Third Argument is the current date(Date.Now)
The code will be like
Dim hours As Long = DateDiff(DateInterval.Hour, retrievedDate, Date.Now)
|
|
|
|
|
You can also subtract dates:
If (RetrievedDate.Subtract(Now).TotalHours >= 1) Then
End If
|
|
|
|
|
Hi, dear all,
I have an existing VB6 project installed in my computer, I have its source codes. Now I will create another project based on it.
The strange thing is that there is a reference which is always pointed to the previous project, all others are ok after modification, only this one doesn't work. I open the .vbp file, modify the path mannually, save it. but when I open the project, it still points to previous project path, I use browse button in reference dialog to relocate it, it still not change.
What should I do? If I remove the prevois project, I am afraid of that the new project won't work since that file is missing.
Thanks!
|
|
|
|
|
I used to move project between machines without any problem.
Edit the vbp files to change the paths using notepad, make sure you also change any of the controls locations to the correct depth, i used to find occasionally had one too many ../../../ depending on which machine i was on.
|
|
|
|
|
Dave,
Thanks! Yes, I open the .vbp in notepad, the strange thing is that in .vbp file the path is in current project, but when I open the project from VB6, and click "Reference", that reference's path is pointing to previous project again. If I save the project, and open .vbp file, the refernece path is changed back to previous project.
There are more than 10 reference, all others are ok, only this one doesn't work.
Did you encounter this issue before?
|
|
|
|
|
To be honest its been that long since i went near vb6, i can't remember..........hopefully never need to go near it again.
|
|
|
|
|
I also wish this is the last project in VB6. Thanks!
|
|
|
|
|
Why don't you copy the code to new files in a new project? (Know it is a boring way. But might help you if you lack time)
|
|
|
|
|
Hi I'm currently developing graphics manipulation program with GDI+ under Visual Studio 2010 Ultimate RC - the language is Visual Basic. I'm writing the program on my laptop and I test it on my desktop PC, my desktop PC is:
OS: Windows Xp SP2
.NET Framework 3.5 SP1
CPU: 1.8GHz P4 Northwood
RAM 1GB
My Laptop is:
TravelMate 5720G
OS: Windows 7 Ultimate
.NET Framework 4
The application I'm developing uses GDI+ for all graphics manipulations. My project framework is .NET 3.5 SP1. The compiled executable used to work fine on my old desktop PC, but today I tried to start it and windows XP gave me the following error:
'(myprogram)has encountered a problem and needs to close. Send Error Report/Don't send'
The program I'm developing is for educational purposes in educational centre near my town and
there teachers have only two PC with windows vista and others run on XP, so its very important for me to get my app working on XP.
Thank you in advance.
|
|
|
|
|
O.G.I. wrote: (myprogram)has encountered a problem and needs to close
that basically tells me you did not meticulously provide error handling in your app.
You need to add some try-catch constructs, where an exception when caught also gets displayed, say using MessageBox.Show(exception.ToString())
The first place to insert such try-catch construct is in your very first code (so it covers everything that gets executed on the main thread from there), so go search for file program.vb
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Are you trying to run a 'release' compile?
If so, uninstall and install a 'debug' compile - you should get a more meaningful error message concerning an unhandled error.
|
|
|
|
|
|
is that Excel screenshot just an example of the kind of dialog, or is it actually Excel having a problem?
you do know Office automation is tricky, and particular to each and every version of Office? you cannot assume a solution that automates Office 2003 to also work on Office 2007 or 2010, they are not compatible.
please try and provide more detailed and more accurate information, so somebody can provide specific help.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|