|
|
Hi,
You can use following library for exporting to Excel :
CarlosAg Excel Xml Writer Library[^]
And for exporting to word :
Gios WORD .NET Library (using RTF specification)[^]
For exporting to word/excel, you must have to iterate through Row of datagridview rows, using following code snippet
For Each currentRow As DataRow In DataGridView1.Rows
'Use the values in current cell using following syntax.
currentRow.Cells(0).Value
currentRow.Cells(1).Value
currentRow.Cells(3).Value
'until all cells are covered.
Next
Alternatively if you are looking for only copying the data to excel/word, just select the data copy using (ctrl+c) and paste to word/excel (This will work with .NET framework version 2.0 and greater).
Hope I answered your query.
Thanks,
Ashu
dnpro
"Very bad programmer"
|
|
|
|
|
You can do one thing. Write the data of your DGV to a CSV (comma separated value) file.
Whenever a user opens a CSV (on a machine having MS-Office) it will get open in MS-Excel by default.
Here's a raw code snippet
for each row in DGV
get value of cell and store it in string
append , (i.e. comma)
end for
trim last character of string //(because it would contain last appended comma)
write this string to file "file.csv"
save the file
Whenever user open this CSV it will get open in MS-Excel.
If a user does not have MS-Excel he/she may do one thing. Right click the file and open it in notepad.
Hope this help you out.
|
|
|
|
|
Hi,
Forgive me if this is a silly question. I'm new to this.
How can one find out the height and width of the scrollbars of a treeview control?
I have a treeview which i'm trying to resize when the form is resized.
I'm doing this;
Me.TreeView1.Height = Me.ClientSize.Height - x
I need to figure out 'x' so that the scrollbar stays inside the form!
|
|
|
|
|
You should make sure the treeview stays inside the form. The scrollbar will follow automatically.
Appropriate anchoring and docking will do that for you.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
जय हिंद
|
|
|
|
|
d@nish wrote: You should make sure the treeview stays inside the form
That is what i was trying to do with the piece of code i'd posted.
But unless i subtract a certain value (which i assume is the height of scrollbar), the treeview's scrollbar strays out of the form!
interestingly if i simply use the docking property (Fill), the resizing works fine but the scrollbar is never shown. hence my attempt to do it manually.
|
|
|
|
|
Assuming the treeview is in the left part of the form along the height, anchor it to top, left and bottom. Also make sure scrollable property is true.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
जय हिंद
|
|
|
|
|
Thanks d@nish.
Got it to work. I had to delete the original treeview and add a new one.
I must have messed-up some other property.
|
|
|
|
|
Good Morning
I am having a common problem I suppose but it seems I cannot find a solution... Don't know if I am searching for the correct thing.... If you know of a place to look please let me know...
In my DataGridView if I park on a new line and hit F2 (or ALT+Down) and hit enter to go to the next row... It doesn't select the value that is selected. I have to go up and down (choose another and the first selected one again) for the value in the combo to update the value in the grid.
Should I update the value manually on the Combo OnLeave or something like that...
Thanks for your help,
Christiaan
|
|
|
|
|
Hi,
In short: yes.
You can use the SelectedIndexChanged event of the combobox to get the value and then you have to write code to actually update the value in the DataTable or DataSet.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hello ! I want to add a button in a listview, can you help me how to do it?
thank you in advance
|
|
|
|
|
Not in a listview, use a datagridview for holding a control in a cell.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Is it possible to start a process (that shows a form) if the windows service I've created is running with User credentials? I know if I run the service as LocalSystem I can interact with the desktop but I need to transmit data over a TCP connection.
I'm currently receiving this error and can't seem to find a solution:
"Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application."
PS - I'm using VS 2005 so no fancy new stuff please.
|
|
|
|
|
Jim Dowthwaite wrote: Is it possible to start a process (that shows a form) if the windows service I've created is running with User credentials?
Yes and no. Yes, it's possible, but only if the service is running as LocalSystem with the "Interact with Desktop" option enabled. The problem with this is that you may show a form without a user being logged in, in which case, your code will sit there forever waiting for a user that will NEVER see the form, even if someone logs in afterwards.
You SHOULD be writing two applications. The service that does your work, and a seperate UI application that communicates with the service and handles ALL UI work required.
|
|
|
|
|
I do have a second application that shows the work. Basically, the service is a TCP listener that waits for a message. When a message arrives, the service saves it as an XML file in a watched directory. When the folder watcher in the service sees the new file, I need the service to launch the secondary application that handles the new file.
If I run the service as LocalSystem, the TCP listener won't work. If I run it as User the process won't display the secondary application...
|
|
|
|
|
Well, the code that launches this process needs to be moved to the UI app, not the service. The service can send the UI app the message to do this since there may not be a user, or the correct user, logged in at the time the file shows up.
|
|
|
|
|
That is the problem though...the UI app is just a single form that reads in the XML file the service downloaded and displays a message to the user or does some background work.
Is there no way to start the UI process from the service authenticated as the LocalSystem?
|
|
|
|
|
If the service is logged in as anything other than LocalSystem, no, there isn't.
So what's stopping you from turning that little form app into something shows a little icon in the System Tray and can be called upon to show the downloaded file whenever necessary? Launching another application from that app will work very easily.
|
|
|
|
|
Hello all, does anyone have anyinformation on the following bug?
Steps:
1) put 3 textboxes on a form
2) in the leave event of textbox1 - disable textbox2
3) run the code - hit the tab key while in textbox1
4) the cursor remains in textbox1 - most likely because at the time of the keypress of the tab key textbox2 was enabled...now it's not so it lost where it should go...
I have a couple of work arounds but just curious if anyone knows of this and any "fix" plans...
Thank you.
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
|
|
|
|
|
This is not a bug and there's no "fix". This is actually the expected behavior.
The focus does not get transferred to the next control until AFTER the Leave event handler is finished executing and the remaining event handlers (Validating, Validated, LostFocus, ...) are finished executing for the control losing the focus. By the time the execution gets to calling Focus on the next control (as a result of you hitting tab), the control is already disabled by you setting it's Enabled property to False.
|
|
|
|
|
Thank you for your reply...but it's not my expected behavior
This is 1 work around (doesn't handle a shift-tab scenerio but handles a normal tab)
Private Sub TextBox2_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Enter
If Not TextBox2.Enabled Then My.Computer.Keyboard.SendKeys("{TAB}")
End Sub
There's another way through the keyup event of the form...be nice if I didn't have to put this in either every control or form...
Thanks again.
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
|
|
|
|
|
This is klugy to say the least. I'd probably change this out for enabling/disabling the TabStop property of TextBox2 before I start using the problem-prone solution of SendKeys.
|
|
|
|
|
If you are refering to this...it doesn't work
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
TextBox2.TabStop = False
TextBox2.Enabled = False
End Sub
'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
|
|
|
|
|
I said it would probably be something I would look at. I didn't say I had any code.
|
|
|
|
|
nlarson11 wrote: but it's not my expected behavior
People always expect strange things from machinery
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
TextBox2.TabStop = TextBox1.Text.Trim().Length > 0
'TextBox2.Enabled = TextBox2.TabStop for visual feedback.
End Sub
If you just want to move the focus to the "next" control, try this;
Me.ActiveControl.SelectNextControl(sender, True, False, True, True)
nlarson11 wrote: be nice if I didn't have to put this in either every control or form...
Well, good news is that you can inherit behavior. Next, go to the solution-explorer and right-click to "Add a new Item". From the dialog presented, choose "Inherited Form". If you press "OK", it'll ask what Form you want to inherit from. Point this to your "Form1". The same thing is possible with components.
I are troll
|
|
|
|