|
Don't double post just b/c you were incapable of thinking of an intelligent subject. Your posts can be edited.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I generally code for using VB.NET 2.0 and Visual Studio 2008.
I have a datagrid view bound to a dataset stored in xml file. I have implemented
several custom datagridviewtextboxcell controls - one which displays a box with a
colour beside a number. Another which displays a line of varying width beside it's
value.
These cells are drawn correctly when the value is changed, however when the form is
loaded and the datagriddview filled with data, all the cells are not painted. Only
when I select the cell by clicking does the cell repaint - this has been causing all
sorts of trouble.
I have attempted several workarounds, including a timer tick event hooked to the
invalidate method of the dgv and each displayed cell individually. Any ideas;
I probably have missed something simple.
The sample below is the custom control for the color cell - it will not work right
out of the box as it requires the Autodesk AutoCAD 2008 API
Public Class AcColorCell
Inherits DataGridViewTextBoxCell
<DebuggerNonUserCode()> _
Protected Overrides Sub Paint(ByVal graphics As Graphics, ByVal clipBounds As Rectangle, ByVal cellBounds As Rectangle, ByVal rowIndex As Integer, ByVal elementState As DataGridViewElementStates, ByVal value As Object, _
ByVal formattedValue As Object, ByVal errorText As String, ByVal cellStyle As DataGridViewCellStyle, ByVal advancedBorderStyle As DataGridViewAdvancedBorderStyle, ByVal paintParts As DataGridViewPaintParts)
'formattedValue = Nothing
MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)
If Me.RowIndex < 0 Then Exit Sub
Dim ColorBoxRect As New Rectangle(cellBounds.X, cellBounds.Y, cellBounds.Width - 1, cellBounds.Height - 3)
ColorBoxRect.Inflate(-1, -1)
ColorBoxRect.Width = 18
ColorBoxRect.Offset(1, 0)
Dim TextBoxRect As New RectangleF(cellBounds.X + ColorBoxRect.Width + 4, _
cellBounds.Y, cellBounds.Width - 1, cellBounds.Height - 1)
Dim cellBackground As SolidBrush
If Not Me.Value Is DBNull.Value Then
If Me.Value <> 0 Then
Dim AcColor As Autodesk.AutoCAD.Colors.Color
Dim ColorValue As Short = CShort(Me.Value)
AcColor = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, ColorValue)
Dim r As Byte = AcColor.ColorValue.R
Dim g As Byte = AcColor.ColorValue.G
Dim b As Byte = AcColor.ColorValue.B
Dim Color As Drawing.Color = Drawing.Color.FromArgb(r, g, b)
cellBackground = New SolidBrush(Color)
graphics.FillRectangle(cellBackground, ColorBoxRect)
graphics.DrawRectangle(Pens.Black, ColorBoxRect)
graphics.DrawString(AcColor.ToString, cellStyle.Font, System.Drawing.Brushes.Black, TextBoxRect)
cellBackground.Dispose()
End If
End If
End Sub
End Class
Public Class AcColorColumn
Inherits DataGridViewColumn
Public Sub New()
MyBase.CellTemplate = New AcColorCell
End Sub
End Class
As below, the code for the lineweight control
Public Class AcLineweightCell
Inherits Windows.Forms.DataGridViewTextBoxCell
'skip the following while debugging
<DebuggerNonUserCode()> _
Protected Overrides Sub Paint(ByVal graphics As System.Drawing.Graphics, ByVal clipBounds As System.Drawing.Rectangle, ByVal cellBounds As System.Drawing.Rectangle, ByVal rowIndex As Integer, ByVal cellState As System.Windows.Forms.DataGridViewElementStates, ByVal value As Object, ByVal formattedValue As Object, ByVal errorText As String, ByVal cellStyle As System.Windows.Forms.DataGridViewCellStyle, ByVal advancedBorderStyle As System.Windows.Forms.DataGridViewAdvancedBorderStyle, ByVal paintParts As System.Windows.Forms.DataGridViewPaintParts)
MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)
If Me.RowIndex < 0 Then Exit Sub
If Not Me.Value Is DBNull.Value Then
If Me.Value <> "" Then
'Get value of cell
Dim cellvalue As String = Me.Value
'Get AutoCAD lineweight of value
Dim lwconv As AcDb.LineWeightConverter = New AcDb.LineWeightConverter()
Dim lw As AcDb.LineWeight = Nothing
'Get the number of pixels that represent the lineweight
Dim px As Integer = GetLineweightPixel(cellvalue)
'Get rectangle where we can draw the lineweight
Dim lwrect As New Rectangle(cellBounds.X, cellBounds.Y, cellBounds.Width - 1, px)
lwrect.Width = 70
lwrect.Height = px
'Offset the rectangle from the top of the cell to center the lineweight display
lwrect.Offset(0, Math.Round(cellBounds.Height / 2) - CInt(Math.Round(px / 2)))
'Get rectangle where we can draw the cell value
'Dim txrect As New RectangleF(cellBounds.X, lwrect.Width + 4, cellBounds.Width - 1, cellBounds.Height - 1)
Dim newfont As New Font("Tahoma", 8.25, FontStyle.Regular, GraphicsUnit.Pixel)
Dim cellBackground As New SolidBrush(Color.Black)
graphics.FillRectangle(cellBackground, lwrect)
cellBackground.Dispose()
End If
End If
End Sub
black holes happened when God divided by zero
|
|
|
|
|
I suspect the problem is with the event you are using to paint the cells. I have not used custom controls in a gridview but I do paint individual cells accoring the data in the row. Explore RowPrePaint and there is a cell paint event that may work as well.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Can I Convert PDF file in Crystal Reports in vb.net 2005
Please If any One Have A Solution Please Give Me And Give also the Code how to Convet
Please Help Me One This Topics Please ............
|
|
|
|
|
You can't convert a PDF file to Crystal Report.
|
|
|
|
|
Can I Convet Word file in Crystal Report ?
|
|
|
|
|
No, you can't convert anything to Crystal Report.
|
|
|
|
|
Hi,
How can I create a multiline listview in VB.net(2008)
I converted some code already:
Public Class MultiLineListview
Inherits System.Windows.Forms.ListView
Dim _Font As Font = MyBase.Font
Sub New()
Me.OwnerDraw = True
Me.View = Windows.Forms.View.Details
Me.FullRowSelect = True
Me.HoverSelection = False
End Sub
Protected Overrides Sub OnDrawColumnHeader(ByVal e As System.Windows.Forms.DrawListViewColumnHeaderEventArgs)
e.DrawDefault = True
MyBase.OnDrawColumnHeader(e)
End Sub
Protected Overrides Sub OnDrawSubItem(ByVal e As System.Windows.Forms.DrawListViewSubItemEventArgs)
On Error Resume Next
If e.ItemIndex > -1 And e.ItemIndex < Me.Items.Count Then
Dim sText As String = e.SubItem.Text
Dim sLines() As String = Split(sText, vbCrLf)
If InStr(1, e.ItemState.ToString.ToLower, "selected") > 0 Then
e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds)
Else
e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds)
End If
e.Graphics.DrawRectangle(SystemPens.Control, e.Bounds)
e.Graphics.DrawString(sText, Me.Font, SystemBrushes.WindowText, e.Bounds.Left, e.Bounds.Top)
End If
MyBase.OnDrawSubItem(e)
End Sub
Protected Overrides Sub OnCreateControl()
On Error Resume Next
Me.Items.Clear()
End Sub
End Class
However I can't change the height of each row
For a listbox this code works fine
Protected Overrides Sub OnMeasureItem(ByVal e As System.Windows.Forms.MeasureItemEventArgs)
On Error Resume Next
If e.Index > -1 And e.Index < Me.Items.Count Then
Dim sSize As SizeF
Dim sText As String = Me.Items(e.Index).ToString()
'Dim sLines() As String = Split(sText, vbCrLf)
sSize = e.Graphics.MeasureString(sText, Me.Font)
e.ItemHeight = sSize.Height '* (sLines.GetUpperBound(0))
End If
MyBase.OnMeasureItem(e)
End Sub
But It won't work for a listview
|
|
|
|
|
First, get rid of the "On Error Resume Next". That stuff has been deprecated and replaced with Try/Catch blocks. Also, eating exceptions and doing nothing with them is really bad practice.
Next, the ListView doesn't expose any kind of MeasureItem event, so it's no surprise that it doesn't work.
As far as I know, the only way to change the item height is to change the ImageList size property to an appropriate size to get the height you want.
|
|
|
|
|
Sorry that I didn't replay sooner!
The on error statement was just copyed from someone else his code. Normely I adapted the code but only after i got it to work. but here for measering a listview item I did not found something working.
So if someone has an option/idee how I can implement the measering of the item(s) it helps me a lot
Thanks
|
|
|
|
|
There is no method exposed by the ListView control that allows you to meaure the item in a given box.
The only way to do it would be to create your own version of the ListView control and replace all the painting code with your own.
Frankly, I'd find it easier, cheaper, and faster, to find a third party control that offers the functionality you need.
|
|
|
|
|
|
Did you manage to find an answer ?
Im looking for a Wordwrap solution to listview using owner draw, just cant find mutch info on it
DB
|
|
|
|
|
No.
Like dave wrote.
this doesn't work for listview
Jan
|
|
|
|
|
Hi,
i have two textbox,one button & datagrid.Now i insert datas into DB(access) when i click the button @ the same time show information in datagrid...So retrieve from DB
This result normally ill cme.but last insert datas only missing.
so i want to refresh DB in same button....
Plz give me solution..
Kannan
|
|
|
|
|
This question made absolutely no sense. I have no idea what you're trying to do.
|
|
|
|
|
Best way is reload the data into datagrid.
|
|
|
|
|
Hi
1. I migrated vb6 project to vb.net project.
2. The msdatagrid in vb6 is migrated to vb.net axdatagrid
3. while i tried to bind data to that axgrid like
ReferenceGrid.DataSource = ds.Tables(0)
it shows error as cannot cast .....
4. Then i used this code to caste it
ReferenceGrid.DataSource = CType(ds.Tables(0), msdatasrc.DataSource)
5. still i cannot bind datasource to axgrid getting error as:
Unable to cast object of type 'System.Data.DataTable' to type 'msdatasrc.DataSource'
6. Can any one give me code to bind data to converted axdatagrid.
--------------------------------------------------------------------------------
chandra shekar thota
|
|
|
|
|
You cannot bind a .NET type to the old FlexGrid. Replace the old grid with the DataGridView in the Toolbox and then you can bind that to your .NET DataSet or DataTable object. Of course, if there's other code that manipulates the old grid, you'll have to replace that code with something that does what you need in the DGV.
|
|
|
|
|
Hi Dave,
Excellent Answer. I tried to use new grid and confused whether to use Datagrid or DataGridView. I also found all event which are there in VB6 Grid are not there in VB.Net Grids.Please suggest me some thing to implement this. I am looking for add button control in vb.net grid also.
Suggest me.
modified on Saturday, December 27, 2008 2:57 AM
|
|
|
|
|
There is no button in the grid. Normally, you would supply this button seperately and supply an appropriate input form or control to create a new record in the DataSet/DataTable you have the grid bound to.
|
|
|
|
|
Hi All,
I am creating an application in vb.net 2008 and Sql server 2005
I want to create a shared folder in the Server system, Than can be acceasable from all the Other System.
And This file using all the User Access Rights.
How can I create the Access Rights
Arindam Banerjee
Sr. Software Developer
Rance Computer Pvt Ltd.
Kolkata (India)
|
|
|
|
|
Use following code
Dim strPath As String = "C:\Gaurav"
Dim dir As String = IO.Path.Combine(strPath, "Temps")
Dim dirSecurity As New System.Security.AccessControl.DirectorySecurity
Dim rul As New Security.AccessControl.FileSystemAccessRule("Everyone", Security.AccessControl.FileSystemRights.FullControl, Security.AccessControl.AccessControlType.Allow)
dirSecurity.AddAccessRule(rul)
IO.Directory.CreateDirectory(dir, dirSecurity)
Dim sharename As String = "ServerFolder"
Dim cmdstring As String = "cmd /c net share """ & sharename & """=""" & dir & """" & " /unlimited"
Shell(cmdstring)
|
|
|
|
|
The basic code behind creating a share can be found here[^]. It's in C#, but is easily translatable to VB.NET using any online code conversion tool.
|
|
|
|
|
-------------------------------------------------------------------
:::: Great Indian Developer Summit 2009 - GIDS .Net ::::
:::: 24 April 2009 ::::
:::: J N Tata Auditorium, IISc, Bangalore ::::
:::: http://www.developersummit.com ::::
-------------------------------------------------------------------
Dear Group members,
The economic downturn will run out of steam trying to outdo the 'ready and waiting' software professional. Packed with premium knowledge, action plans and advise from been-there-done-it veterans, creators, and visionaries, the 2009 edition of Great Indian Developer Summit features focused sessions, case studies, workshops and power panels that will transform you into a force to reckon with.
Dot Net Speakers at the 2009 edition of GIDS include: Todd Anglin, Beat Schwegler, Chad Hower, Donald Belcham, Venkat Subramaniam, Kevin Babcock, Stephen Forte, Nikhil Kothari and Prabhu Sunderraman. The conference this year has sessions on Visual Studio 2008 & .NET 3.5, ADO.NET Entity Framework, T-SQL, ASP.NET AJAX 4.0, Databases/SQL Server/Language Integrated Query (LINQ), C# 4.0/WF/WCF/WPF, BizTalk Server/BPM/SOA, SharePoint & Search, Visual Studio Team System, ASP.Net MVC, Silverlight, Spring .NET, DWM, cool and new technologies from the Microsoft Stables. and much more. Please have a look at http://www.developersummit.com/speakers.html for more info on the speakers and the sessions.
Register before the 29th of December for Rs. 1,999/-. Besides the learning at the GIDS.Net conference on Wednesday, the 22nd of April, this fee also includes:
1. Discount of 35% on the standard fee
2. Assured Gift - GIDS 2009 Cult T-shirt (upon receipt of payment on or before Jan 12 2009)
3. Entry into a lucky draw for the following gifts: Sony WEGA 29 inches (1), Mac Air Book (1), Wireless Mouse (50 nos), Apple iPOD 120 GB (5 nos).
4. Lunch and refreshments
5. Conference materials
6. Complimentary invitation to Cyrus Broacha's show at the Great Indian Developer Awards on Saturday, the 25th of April 2009
So hurry up and register now under the GIDS Loyalty discount scheme: http://www.developersummit.com/registration.html
Wishing you and your family a Merry Christmas and a wonderful year ahead.
Thanks,
Shaguf
http://www.developersummit.com/
info@developersummit.com
|
|
|
|
|