|
Hi,
Can anyone tell me is this possible.....
I want to fill the DataGrid. I have 5 columns selected in the Query using Joins from 2 Tables.
I want to Fill the Datas in the Grid along with it, add 2 more columns to be added in the Grid, but the 2 added columns should be used as Date Picker.
This is for VB.NET application. and it is a Very urgent task to Complete.
pls help me out in doing this Task.
(Note: I'm NEW to .NET)
Thanx and Regards,
Tthangaraj P.V.
tthangarajpv@yahoo.com
|
|
|
|
|
Hi,
There is a great sample for doing this in MSDN. I am just giving it.
Imports System<br />
Imports System.Data<br />
Imports System.Windows.Forms<br />
Imports System.Drawing<br />
Imports System.ComponentModel<br />
<br />
' This example shows how to create your own column style that<br />
' hosts a control, in this case, a DateTimePicker.<br />
Public Class DataGridTimePickerColumn<br />
Inherits DataGridColumnStyle<br />
Private timePicker As New DateTimePicker()<br />
' The isEditing field tracks whether or not the user is<br />
' editing data with the hosted control.<br />
Private isEditing As Boolean<br />
<br />
Public Sub New()<br />
timePicker.Visible = False<br />
End Sub<br />
<br />
Protected Overrides Sub Abort(ByVal rowNum As Integer)<br />
isEditing = False<br />
RemoveHandler timePicker.ValueChanged, _<br />
AddressOf TimePickerValueChanged<br />
Invalidate()<br />
End Sub<br />
<br />
Protected Overrides Function Commit _<br />
(ByVal dataSource As CurrencyManager, ByVal rowNum As Integer) _<br />
As Boolean<br />
timePicker.Bounds = Rectangle.Empty<br />
<br />
AddHandler timePicker.ValueChanged, _<br />
AddressOf TimePickerValueChanged<br />
<br />
If Not isEditing Then<br />
Return True<br />
End If<br />
isEditing = False<br />
<br />
Try<br />
Dim value As DateTime = timePicker.Value<br />
SetColumnValueAtRow(dataSource, rowNum, value)<br />
Catch<br />
End Try<br />
<br />
Invalidate()<br />
Return True<br />
End Function<br />
<br />
Protected Overloads Overrides Sub Edit( _<br />
ByVal [source] As CurrencyManager, _<br />
ByVal rowNum As Integer, _<br />
ByVal bounds As Rectangle, _<br />
ByVal [readOnly] As Boolean, _<br />
ByVal instantText As String, _<br />
ByVal cellIsVisible As Boolean)<br />
Dim value As DateTime = _<br />
CType(GetColumnValueAtRow([source], rowNum), DateTime)<br />
If cellIsVisible Then<br />
timePicker.Bounds = New Rectangle _<br />
(bounds.X + 2, bounds.Y + 2, bounds.Width - 4, _<br />
bounds.Height - 4)<br />
<br />
timePicker.Value = value<br />
timePicker.Visible = True<br />
AddHandler timePicker.ValueChanged, _<br />
AddressOf TimePickerValueChanged<br />
Else<br />
timePicker.Value = value<br />
timePicker.Visible = False<br />
End If<br />
<br />
If timePicker.Visible Then<br />
DataGridTableStyle.DataGrid.Invalidate(bounds)<br />
End If<br />
End Sub<br />
<br />
Protected Overrides Function GetPreferredSize( _<br />
ByVal g As Graphics, _<br />
ByVal value As Object) As Size<br />
Return New Size(100, timePicker.PreferredHeight + 4)<br />
End Function<br />
<br />
Protected Overrides Function GetMinimumHeight() As Integer<br />
Return timePicker.PreferredHeight + 4<br />
End Function<br />
<br />
<br />
Protected Overrides Function GetPreferredHeight(ByVal g As Graphics, ByVal value As Object) As Integer<br />
Return timePicker.PreferredHeight + 4<br />
End Function<br />
<br />
<br />
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal [source] As CurrencyManager, ByVal rowNum As Integer)<br />
Paint(g, bounds, [source], rowNum, False)<br />
End Sub<br />
<br />
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal [source] As CurrencyManager, ByVal rowNum As Integer, ByVal alignToRight As Boolean)<br />
Paint(g, bounds, [source], rowNum, Brushes.Red, Brushes.Blue, alignToRight)<br />
End Sub<br />
<br />
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal [source] As CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)<br />
Dim [date] As DateTime = CType(GetColumnValueAtRow([source], rowNum), DateTime)<br />
Dim rect As Rectangle = bounds<br />
g.FillRectangle(backBrush, rect)<br />
rect.Offset(0, 2)<br />
rect.Height -= 2<br />
g.DrawString([date].ToString("d"), Me.DataGridTableStyle.DataGrid.Font, foreBrush, RectangleF.FromLTRB(rect.X, rect.Y, rect.Right, rect.Bottom))<br />
End Sub<br />
<br />
Protected Overrides Sub SetDataGridInColumn(ByVal value As DataGrid)<br />
MyBase.SetDataGridInColumn(value)<br />
If Not (timePicker.Parent Is Nothing) Then<br />
timePicker.Parent.Controls.Remove(timePicker)<br />
End If<br />
If Not (value Is Nothing) Then<br />
value.Controls.Add(timePicker)<br />
End If<br />
End Sub<br />
<br />
Private Sub TimePickerValueChanged(ByVal sender As Object, ByVal e As EventArgs)<br />
Me.isEditing = True<br />
MyBase.ColumnStartedEditing(timePicker)<br />
End Sub<br />
End Class<br />
<br />
Namespace DataGridColumnStyleExample<br />
Public Class MyForm<br />
Inherits Form<br />
<br />
Private namesDataTable As dataTable<br />
Private myGrid As DataGrid = New DataGrid()<br />
Public Sub New()<br />
<br />
InitForm()<br />
<br />
namesDataTable = New DataTable("NamesTable")<br />
namesDataTable.Columns.Add(New DataColumn("Name"))<br />
Dim dateColumn As DataColumn = _<br />
New DataColumn("Date", GetType(DateTime))<br />
namesDataTable.Columns.Add(dateColumn)<br />
Dim namesDataSet As DataSet = New DataSet()<br />
namesDataSet.Tables.Add(namesDataTable)<br />
myGrid.DataSource = namesDataSet<br />
myGrid.DataMember = "NamesTable"<br />
AddGridStyle()<br />
AddData()<br />
End Sub<br />
<br />
Private Sub AddGridStyle()<br />
Dim myGridStyle As DataGridTableStyle = _<br />
New DataGridTableStyle()<br />
myGridStyle.MappingName = "NamesTable"<br />
<br />
Dim nameColumnStyle As DataGridTextBoxColumn = _<br />
New DataGridTextBoxColumn()<br />
nameColumnStyle.MappingName = "Name"<br />
nameColumnStyle.HeaderText = "Name"<br />
myGridStyle.GridColumnStyles.Add(nameColumnStyle)<br />
<br />
Dim timePickerColumnStyle As DataGridTimePickerColumn = _<br />
New DataGridTimePickerColumn()<br />
timePickerColumnStyle.MappingName = "Date"<br />
timePickerColumnStyle.HeaderText = "Date"<br />
timePickerColumnStyle.Width = 100<br />
myGridStyle.GridColumnStyles.Add(timePickerColumnStyle)<br />
<br />
myGrid.TableStyles.Add(myGridStyle)<br />
End Sub<br />
<br />
Private Sub AddData()<br />
Dim dRow As DataRow = namesDataTable.NewRow()<br />
dRow("Name") = "Name 1"<br />
dRow("Date") = New DateTime(2001, 12, 1)<br />
namesDataTable.Rows.Add(dRow)<br />
<br />
dRow = namesDataTable.NewRow()<br />
dRow("Name") = "Name 2"<br />
dRow("Date") = New DateTime(2001, 12, 4)<br />
namesDataTable.Rows.Add(dRow)<br />
<br />
dRow = namesDataTable.NewRow()<br />
dRow("Name") = "Name 3"<br />
dRow("Date") = New DateTime(2001, 12, 29)<br />
namesDataTable.Rows.Add(dRow)<br />
<br />
dRow = namesDataTable.NewRow()<br />
dRow("Name") = "Name 4"<br />
dRow("Date") = New DateTime(2001, 12, 13)<br />
namesDataTable.Rows.Add(dRow)<br />
<br />
dRow = namesDataTable.NewRow()<br />
dRow("Name") = "Name 5"<br />
dRow("Date") = New DateTime(2001, 12, 21)<br />
namesDataTable.Rows.Add(dRow)<br />
<br />
namesDataTable.AcceptChanges()<br />
End Sub<br />
<br />
Private Sub InitForm()<br />
<br />
Me.Size = New Size(500, 500)<br />
myGrid.Size = New Size(350, 250)<br />
myGrid.TabStop = True<br />
myGrid.TabIndex = 1<br />
Me.StartPosition = FormStartPosition.CenterScreen<br />
Me.Controls.Add(myGrid)<br />
End Sub<br />
<br />
<STAThread()> _<br />
Public Shared Sub Main()<br />
Application.Run(New MyForm())<br />
End Sub<br />
End Class
|
|
|
|
|
|
Hi there -
i have to implement a remote control for clients. this control should be able to lock the client-workstation - in simple words: monitor black, keyboard and mouse locked.
I develope the program in VB.net and on the clients a service will run. and within this service, i want to call a function that does the things for me i just talked about.
but i have no idea what function (i think it is a win API function in GDI32) i have to use to do the locking. or has anyone a better idea?
i am open for all suggestions.
thanks a lot for all replies.
happy coding.
tom
|
|
|
|
|
There is no one function that will lock the keyboard and mouse. You have to write code to hook the keyboard and mouse and eat any messages that are sent your way from the keyboard and mouse drivers. Unfortunately, you can't keep the user from using Ctrl-Alt-Del. This key combination cannot be trapped. There is a great article on CodeProject by Michael Kennedy called "Global System Hooks in .NET"
[^] that demonstrats this technique.
Your service must also be set to "Allow interaction with Desktop" so that you can put up a form that covers the entire desktop area and tag that form as TopMost.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
thank you very much for your hints.
the article seems to be what i was lookin' for ...
do you have an example how this thing with "allow interaction with desktop" works?
anyway- thanks for your help.
tom
|
|
|
|
|
Easy. When you instlal your service on the client, go into the Services control panel and find your service. Double-Click on it to bring up its properties and click on the LogOn tab. Make sure it is using the Local System Account and click on the Allow Service to interact with desktop checkbox. Click OK and your done.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The hook article is very interesting. but at the moment i'm thinkin' if i could not find an easier solution.
if i put up a form that covers the entire desktop and make it topMost - all i have to do then, is to avoid the user from closing the window by pressing the "x" in the upper right corner or pressing alt+F4. right? maybe i can catch this in a way easier than to hook the keyboard. but then - the user still can press strg+alt+del and kill the form in the taskmanager, can't he?
|
|
|
|
|
tommy_tanaka wrote:
the user still can press strg+alt+del and kill the form in the taskmanager, can't he?
Yep. Locking a machine is not as easy as it would sound. There's really no other way of doing this. There is no function you can call to turn off the keyboard and mouse, simply because there is no practical use for it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
sh*t ... well - what do you think of this idea:
the running service remembers if an form has to be popped up or not. if so, it always checks, if the form is still alive, otherwise it pops it up again.
or better, in the destructor of the form, the object itself checks, if it should popup again or not.
to kill a running service will be much more difficult for an usual user, than just to call strg+alt+delete to kill the form.
what's your thinking about this?
|
|
|
|
|
I've got a question... What's the point behind all of this? Why lock the workstation anyway?
tommy_tanaka wrote:
to kill a running service will be much more difficult for an usual user, than just to call strg+alt+delete to kill the form.
You can't kill just a form. A form is part of an application, or service. And don't put it past any user that they can't figure out what to kill off in the process list, which your service will be apart of...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I know an excellent method of locking the computer, although I'm not sure of any API's that might help, if you could purposely lock the machine or BSOD it (Blue Screen Of Death) - would that be helpful? lol. Try this: On Windows 98 goto Start, Run and type con/con and you get a nice BSOD! hehe
Or... alternatively you could try my more serious solution:
- Set the border of the form to 0 so it has no title bar etc...
- Make the form top-most using the SetWindowPos API
- Disable keyboard and mouse input using the BlockInput API (with params TRUE or 1) call this in a 1 milli second timer!
Now the only key combo that works is C.A.D (or S.A.D as you lot call it) I know this is a pain in WinXP but, there is a way around that with a simple registry hack. Change following in the registry (if it doesn't exist - create the keys and the value)
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\
Create a REG_DWORD value under this key called DisableTaskmgr and set it to 1
Because there is no simple way to do this I have come up with a bit of a patchy method but it works. Watch out for that windows key
Oh yeah one last thing make the background color of the form blue so it looks like a BSOD
|
|
|
|
|
Hey got a question,
I'm using a printe document in my program, My printing goes just fine, along with my print preview. My question, is does anybody know how to at runtime, choose to print to a file, like you were to select that on a print dialog? Setting the path and file to create for this Print to File, I've searched all over and, can't seem to find anything on this, also tried a few different things. I want to do this all without user involvment.
Thanks in advance
|
|
|
|
|
At runtime, you could just write the information to a text file using the normal File methods. You really can't setup a printer to use a FILE: port at runtime. There is no support in the .NET BCL to do this.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks Dave for the reply, figured you would.
But, let me be more clear, as to why I'm trying to do this, maybe you can give me a better solution. At work, when we click the fax button in are program, the MIS department, has that program print the document to a file ( one that is not text and also not a tiff file ) then passing this file to an email that gets sent to are biscom fax server. I'm assuming what they do, is act like printing, but print to a file (sort of like on the option on the print dialog to print to a file instead) and pass this along in the email. If not, I'll have to figure out how to create a tiff file from my print document to make this work.
Thanks for your help
|
|
|
|
|
The printing classes in the .NET BCL currently do not support (correctly anyway...) turning on the "Print To File" option through code. It only allows you to activate the check box on the PrintDialog. Even then, it doesn't work properly and your output will still go to the printer and not a file. This MIGHT be fixed in SP1 for .NET 1.1 and SP3 for .NET 1.0.
You best bet is to "print" your document, I should say "draw" your document, to a Bitmap object and save that as a .JPG, .BMP, or whatever you need and send that image as an attachment in an email.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I figured after not finding anything on printing to a file, as I was wanting to do. Thanks for your help, and suggestions.
|
|
|
|
|
Hello
I want to create a modeless dialog addin in EXCEL by using VB.NET 2002.
I found a following good document and I could successfully compile it. Then I could open a modal dialog in EXCEL.
"Tips and Tricks: Building Microsoft Office Add-ins with
Visual C# .NET and Visual Basic .NET"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchtipstricksbuildingmicrosoftofficeadd-inswithvisualcnetvisualbasicnet.asp
In the document, I changed the following command
selectionForm.ShowDialog()
to
selectionForm.Show()
and I could successfully open modeless dialog.
HOWEVER, this dialog window is hidden under the EXCEL window when the EXCEL window is set to TOP position by clicking its title bar.
In VBA, I know that modeless dialog window is always shown above the EXCEL window when the EXCEL title bar is clicked.
In VB.NET, I want to make my modeless dialog shown always above the EXCEL window like VBA.
I think that the AddOwnedForm() command will be a solution, but I could not done it yet.
If anybody here has experience to create modeless dialog in EXCEL using VB.NET 2002, Please let me know how to do this.
Best Regards,
nnj
Japan
|
|
|
|
|
Hi all,
I am a pure C++ programmer and new in .NET and VB. So sorry for this simle question
I use for tracing in my applications normally following way to have debug levels.
//my_proj_globals.h
#ifdef _DEBUG
extern unsigned int debug level
#define DEBUG_MSG(msg,num) if ((debug_level)&(((unsigned int )1)<
|
|
|
|
|
It's too much to go into here in the forums, but you can do what your thinking of. You'll be using the Trace and Debug classes as well as creating your own Trace Switches with the Switch class. If your really proficient in C++, you should have any trouble at all digging into the Trace and Debug docs here[^] and check out a little example of creating your own Trace Switches here[^].
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave,
I am sorry to mention this, but: How your anwer can be helpful to me? Of course I allready reviewed both links you sent and as I wrote I also played around with trace switches. If you know the answer you could just check it on your PC and then sent to me/or forum, if not... ( "if you really... " is just wasted bits)
Sorry once more.
The points are:
1.I can't find how I can in visual basic print a source file name and a line, where in C++ you have __LINE__ and __FILE__ preprocessor macros
2.How to switch on and off multiple groups of trace messages depending on the global variable.
3.In the documentation some .config file mentioned what is it? I couldn't find some in the project subtee
Thanks you all in advance,
Boni
|
|
|
|
|
Boniolopez wrote:
1.I can't find how I can in visual basic print a source file name and a line, where in C++ you have __LINE__ and __FILE__ preprocessor macros
You can't. The file and line number information is not exposed through the BCL or through compiler constants or directives. The best you can do is a Strack Trace from the System.Diagnostics namespace.
Boniolopez wrote:
2.How to switch on and off multiple groups of trace messages depending on the global variable.
Was covered in the example in the 2nd link. Switch Class[^] allows you to make your own custom Trace switches. The functionality of witch wuold be to let you create your own levels of trace information.
Boniolopez wrote:
3.In the documentation some .config file mentioned what is it? I couldn't find some in the project subtee
The is a file called applicationname.config . The filename matches the name of the .EXE. So if you have myApp.exe, the config filename would be myApp.exe.config. Docs[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
how to display a word document on a click event
yy
|
|
|
|
|
Are you trying to launch Word as a seperate application or are you trying to show a Word window that appears on your own form?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
how to display more than one ,different icons in a picture box and OLE
give code
|
|
|
|
|