|
Hi all !
I want to save the DataGrid Cell Value into an excel file :
...
try
{
mySheetInputData = (Microsoft.Office.Interop.Excel.Worksheet)ExWorkBookInputData.Sheets["Sheet1"];
mySheetInputData = (Microsoft.Office.Interop.Excel.Worksheet)ExWorkBookInputData.ActiveSheet;
mySheetInputData.Name = "mySheet";
...
for (int i = 0; i < RowCount; i++)
{
for (int j = 0; j < ColumnCount; j++)
{
mySheet.Cells[i + 2, j + 2] = dgv.Rows[i].Cells[j].Value;
if (dgv.Rows[i].Cells[j].Value == null || dgvRows[i].Cells[j].Value.Equals(""))
mySheet.Cells[i + 2, j + 2] = 0.0;
}
}
dgv.update();
....
when I save this to an excel file , last cell i fill , show the value of "0.0" , but when I resize or minimize the application or change the cursor in the next cell that fill before , there is no problem to show all value i put to DataGrid Cell.
thanks a lot !
modified 19-May-12 3:02am.
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Edit your question and provide better information - perhaps a simple example of what you have before, what you expect, and what you get would help.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
This is happening because a cell is still in edit mode when it's Value property is read. The new value does not become available until it has been committed and edit mode ended.
As you found out this can be done by moving the focus to another cell or control, but it can also be done programmatically by calling the DataGridView's EndEdit method.
Inserting the following line before you start reading values from the grid should fix the problem.
dgv.EndEdit();
Alan.
|
|
|
|
|
thanks , it solve the problem !
|
|
|
|
|
So I create a new project, planning to use a Grid for layout. According to VS2010 Help, this is found in System.Windows.Controls. I typed the appropriate using clause and added a Grid element to my Form, but that generated an error telling me that no such namespace exists. So I try to add a reference to the project, but there still is no such thing as a namespace called System.Windows.Controls. It's fully documented in Help, of course, and full of useful things, but there is no such thing, if I believe Visual Studio. The help article also mentions that this item is located in the Assembly, PresentationFramework (in PresentationFramework.dll). So I used the Browse tab to search for this dll and add it, too. Found it, but the IDE still claims there is no such thing as a Grid class.
After several hours of screwing with this nonsense, adding and removing using clauses willy nilly, I quit typing it manually and let the Intellisense display its wares. Lo and Behold, there was a Controls selection available under System.Windows, if I slowed down enough to wait for it to display. Typing it directly, exactly as the automated feature typed it, won't work. Is it any wonder that I never finish an app?
The wonder is that I keep trying...
Will Rogers never met me.
|
|
|
|
|
It's just you!
In practice if you look at the help page:
Namespace: System.Windows.Controls
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation It gives the problem away: "Assembly: PresentationFramework" which means it is part of WPF, not WinForms. If you create a WinForms app, then you can't use the Grid Control, as it requires the WPF framework which is XML based.
Depending on what you are trying to do, you might want to use a TableLayoutPanel or Splitter panels instead!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
That's not quite true. You can use the Grid layout in WinForms as you can host WPF content in a WinForm. Whether you'd want to is a different matter.
|
|
|
|
|
I didn't know that! Any links to how? (Not that I want to do it, it would just be for reference)
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
You just need to use an ElementHost object. It's under the WPF tab.
|
|
|
|
|
cheers!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Take a look at this[^]
I have added WPF stuff to a winform, just for fun. I don't do it for real programs.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
Background:
My lady loves the game of Keno, specifically Cleopatra Keno. Her birthday is in 4 weeks, and I have 3 weeks relatively free until classes start again. I'd like to make a Windows version of the game for her to play at home for her birthday. Not only would she love it, but it would save me a ton of money if I could get her used to playing at home instead of a casino. The logic of the game is trivial. The player selects 3 to 10 numbers from a field of 80, places a bet, and presses Go to run a game.In Cleopatra Keno, if the run is a winner, and the last number drawn is one selected by the player, the game awards 12 free runs with doubled payouts. Each run draws 20 numbers from the field. The overall payout is only 90.1%, so it's a lousy money maker, but I have to admit that it's fun when a game starts hitting these bonus rounds over and over... it does happen.
So, I've created a Keno tile class as a user control. It has a button overlaid on a UserControl background with a Text member that represents the number of the tile, set in the constructor for each instance. A Tile contains methods to set and reset states of Selected by the player, Hit during game play, Last hit in a run, et cetera. These are all self-contained functions to control the colors displayed to the user. But how do I lay them out in a rectangular grid, and what's the best way to handle interactions between the game and the user? I think that having the individual tiles raise an event when the user makes a change makes sense, but during the game run, what should control?
The layout question is really the top priority right now. I have to instantiate 80 separate controls and make them display in a grid of 8 rows of 10 columns, and I'm not sure of the most efficient way to accomplish that. I could calculate the XY coordinates for each top left corner and render them that way, but that seems awfully ugly. Is there a better way?
Will Rogers never met me.
|
|
|
|
|
Sorry mate, but that sounds a horrible way to layout the interface. If I were doing this, I would consider drawing the grid out in it's entirety. I would then have a class which represented a single tile, which would contain a Rectangle that represents the tile location on the screen.
I would have a TileContainer class which was responsible for maintaining the collection of tiles and performing operations such as getting the "hit" tile. As a hint, a simple method would be to just iterate through the tiles performing a Rectangle.Contains to see which rectangle contains the point - there are other optimisations you could perform, but on 80 items, this wouldn't be an expensive operation.
|
|
|
|
|
I'll rethink it, but I was really hoping to avoid all the graphics details. The UI crap wastes 95% of my time as it is, and I hate it. I was hoping that using controls I could get around that stuff.
Will Rogers never met me.
|
|
|
|
|
With my solution all you do is draw the lines and draw the text. Heck, you even have the coordinates worked out for you in each tile.
|
|
|
|
|
I definitely think your suggestion is the best suggestion so far!
I do something similar with my webcam security software where there are N webcams.
So I have what I call a rig that contains a collection of cameras.
The numbers of tiles and their row or column is not relevant to the design of the tile as each tile can keep track of it's own position.
If you want to know what is at a particular positiion all you have to do is ask for the tile at that postion - there could be a method such as Rectangle(x,y) within the container class.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
GuyThiebaut wrote: If you want to know what is at a particular positiion all you have to do is ask
for the tile at that postion - there could be a method such as
Rectangle(x,y) within the container class.
Excellent suggestion.
|
|
|
|
|
Roger Wright wrote: I could calculate the XY coordinates for each top left corner
That's how I'd do it. :shrug: But I'm not much good with graphics, so controls are my hammer of choice when I see that kind of nail.
However, won't you allow the user to select sub-groups of numbers? In a "real" game that's done with drawing circles around some of the numbers -- so you may need to use graphics anyway. Or some sort of shift-clicking combined with some visual indication -- or kind of like grouping objects in Visio.
P.S. Or use a DataGridView?
modified 18-May-12 11:51am.
|
|
|
|
|
PIEBALDconsult wrote: won't you allow the user to select sub-groups of numbers?
Of course, by clicking each control. There's no need to have them grouped in any special way. On the real game, you select tiles by poking the screen with a finger; this will just use the mouse.
I've never used a DataGridView before, and don't know if I can stuff a control into one. I'll give it a try!
Will Rogers never met me.
|
|
|
|
|
I'm not sure you understood. Say the user selects { 1 , 2 , 3 , 4 , 5 , 6 } as the main group -- he can also select sub-groups { 1 , 2 , 3 } and { 4 , 5 , 6 } for example.
|
|
|
|
|
Oh! I see. Yes, there are games where this is done, but not on Cleopatra Keno.
Will Rogers never met me.
|
|
|
|
|
Ah. So why play it then? Doesn't it waste paper?
|
|
|
|
|
No, but it does sometimes waste an awful lot of quarters!
Will Rogers never met me.
|
|
|
|
|
Whenever I get into graphics with windows, the actual math way always trumps the user control way, every time. Windows forms and WPF just don't like a lot of controls. On the plus side once you have done the math a few times it really isn't so hard.
|
|
|
|
|
I'm going for a WPF solution. I've never tried it, so it should be an adventure. To start, I'm trying a grid within a grid - the outer for the overall game layout, and the inner for the array of Keno tiles. This should be an interesting adventure...
Will Rogers never met me.
|
|
|
|