|
Thank you for your respond
It will always be one form, but I need the form name or id to close it
and I dont want to hardcode the forms name.
I want basically: Is there a form open, if there is retrieve its id and then say id.close
|
|
|
|
|
What I would do is in your main form I would create a form lavel variable that returns a form i.e
Private OpenForm as Form . I would assign this to the current form that is opened in the procedure that opens the form, and in the procedure that checks if a form is open you can just do this
If Not OpenForm Is Nothing Then
Else
OpenForm.Close
End If
Hope this helps
Happy Coding
|
|
|
|
|
Brilliant, thank you it's working just the way I wanted it to work.
|
|
|
|
|
Pleasure, glad it helped.
Just be sure to make sure you set the OpenForm variable to nothing when the form is closed, else this will not work the second time.
Happy Coding
|
|
|
|
|
Hi, dear all,
I don't know if this is the right place for my post.
I have to projects ( we called them as A and B) created using VB6. A is created several years ago and already formally distributed. Now I create the project B based on project A, they are almost same except some interface and the two project belong to different owners. Since the functionality of these two project are same, so they have some dependency files are also same.
My problem is that if I install only one from the two project, no problem. If I install two project, then uninstall one, the other one doesn't work. it give message like "one of the dependency not correctly registered,.....
Somebody suggests me to use merge module to solve this issue. do you think my case is good to use merge module? if we need to use merge module, do these two project's installation setup file will be recreated to include the merge module to them?
Or you have any good idea? thanks a lot.
|
|
|
|
|
The shared resources (assemblies, activeX controls etc) could indeed be tucked away in their own installation package. Now, it would get confusing if you were to create three setups. It's kinda like having the problem of distributing Sql Express along with your product.
A merge-module would become a part of the installation, similar to other 'prerequisites'. A good place to start is MSDN[^].
I are Troll
|
|
|
|
|
Eddy,
Thanks for your reply.
|
|
|
|
|
Hello, I realize this isn't directly related to VB but I hope someone can help.
I created a WCF windows service that's listening on port 52799. When the service is started as a system user - it listens and other PC's can log into the service without issue. When I try to change the user from system to a domain user (admin to the server where the service is running) and start the service using their crudentials, the service no longer appears to be listening and other PC's timeout attempting connect.
I have added the security permission.demand/assert logic to the service and no change. Can someone help me figure out what a non-system user doesn't work as expected?
Thank you for your time.
Nathan
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
nlarson11 wrote: I realize this isn't directly related to VB
So why post it in the VB forum rather than the WCF forum?
It's time for a new signature.
|
|
|
|
|
nlarson11 wrote: nlarson11 has posted a reply to your message at "Visual Basic":
Hey Rich,
I feel like such and ass inconveniencing you where you had to waste your time reading my misplaced question. May you be on the receiving end of your attitude when you need help.
Thanks again.
Yeah sorry, I see that you are a reasonably long-standing member of CP so you obviously don't need advice from the likes of me.
It's time for a new signature.
|
|
|
|
|
Hi ,
Iam new to vb.net,
I need to create a [rp[erty to datagrid at cell level
i.e
custom property Border color which is something similar to Back color
like
datagridview.rows(0).cells(1).Bordercolor
here Bordercolor should be my custom property
Please help me
Thanks in advance
rasna
|
|
|
|
|
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
|
|
|
|