|
Luis Alonso Ramos wrote:
But for example, if I want to get data from a database, I would have to know about DataSets and DataAdapters and DataReaders (at least of their existance) and then serach for them in the docs.
That's what the table of contents (TOC) is for. When I first started developing for the .NET Framework (back in 1.0 beta 1) I expanded the TOC namespace by namespace and took a glimpse at the available namespace members. Even if you don't have a great memory, most people would at least get a feeling of deja vu if you required a class to do something.
The point I'm trying to make in this instance is that your specific problem could be understood and fixed if you did understand how the DataGrid works (for example; you don't need a DataSet or DataTable - just an IList or IListSource implementation - so the question becomes "How does the DataGrid bind to lists?"), especially when it comes to defined DataSet s (those with explicit table and column definitions). Unfortunately - not knowing your implementation well enough - I can't help as much, but I can at least give you ideas about how to fix it. If you were to dig into the IL disassembly (or decompile using .NET Reflector - but learning IL really is helpful) it would most likely help in figuring out how to work around your particular problem.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
Unfortunately - not knowing your implementation well enough - I can't help as much, but I can at least give you ideas about how to fix it
I think I've fixed it. The problem is that when I set the DataGrid to read only, the add-new-record row is removed. During the OnLeave_grid (private, called by DataGrid 's OnLeave handler), if the control is read only, it tries to create a new AddNewRow at the very end (don't ask me why.) See the following code (from .NET Reflector):
if (this.gridState[0x100000])
{
this.listManager.CancelCurrentEdit();
DataGridRow[] rowArray1 = this.DataGridRows;
rowArray1[this.DataGridRowsLength - 1] = new DataGridAddNewRow(this, this.myGridTable, this.DataGridRowsLength - 1);
this.SetDataGridRows(rowArray1, this.DataGridRowsLength);
} And since the DataTable does not contain any rows, the exception is thrown for accessing index -1.
I wanted to set the DataGrid to read only instead of disabling it, so the user could scroll to review sales, and also to remove the add new row. My fix was to disable the DataGrid if it contains no records (the add new row is still displayed), or make it read only otherwise. That fixed the problem.
Thank you very much for all your help,
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hi, is there any way to trigger an event on a minute change with a DateTime object or something like that?
I would like my program to be noticed when the computer's clock changes. I don't want to do it with a Timer object because it is not synchronized with the PC's clock.
Thanks!
|
|
|
|
|
The computers clock is changing constantly! What are you trying to do?
Are your trying to get notified of a USER change to the system clock? No event like this exists...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Actually, there is: Microsoft.Win32.SystemEvents.TimeChanged .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Doh
So there is! It'll be 2010 before I remember that namespace exists!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
No, I want to get notified every minute!
|
|
|
|
|
This isn't the forum for that (it's a not a C#/.NET problem). Ask in either the Operating Systems directory or visit the Microsoft newsgroups at http://msdn.microsoft.com/newsgroups/[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have a request from a client who wishes to use either the Enter Key or the Arrow Key, as well as the Tab key, to move from field to field in a Windows Form.
Is it possible?
Fred S. Parker
|
|
|
|
|
Yes. Look into KeyPreview , OnKeyPress , and TabIndex .
KeyPreview instructs the framework to send you the keys pressed on the form. OnKeyPress will allow you to see what key is pressed. TabIndex will help you determine which control to give focus to.
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
Instead of walking the tab indexes yourself, just use the Control.GetNextControl method like so in your Form :
if (ActiveControl != null)
ActiveControl.GetNextControl(ActiveControl, true); Use can pass false to the second param to go backward. You should do this when the shift key is down.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
* ducks *
Probably overslept a little too much
Alex Korchemniy
|
|
|
|
|
We can use these methods,such as ZeroMemory() and memcpy() in VC++ to manage memory,so what about those matters in C#?
Thanks!
|
|
|
|
|
Since C# runs in a MANAGED execution environment, these functions are pretty much useless. If you create a new array, the memory is automatically zero'd out. Copying memory is not exactly a feasible operation because of the nature of how objects can be stored in memory. It's always better to use the objects Copy() or Clone() methods, if they support it.
There are always ways to duplicate the functionality to you need in C# other than using the shortcuts these functions provide to C++.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
get it.
^_^Thanks!
Good luck!
momer
|
|
|
|
|
is there anything like ShellExecute in C# to launch other applications?
|
|
|
|
|
|
i am using a treelistview (found here at codeproject) that is populated with potentially hundreds of items (test cases). on start my app will fill the tree with all the test cases and i give the option to reset the tree to inital state, which essentially just reloads again all the test cases to initial state. the problem is when these test cases are all loaded into the tree and all the initial subitems are reset, it's so slow you can watch the tree fill from the top to the bottom with a lot of flickering at the same time. my question is do i need to do double buffering? i don't know how hard double buffering is, but i thought maybe it would be easier just to disable painting while the tree is being filled and have it repaint everything when it's all done. that way i may be able to avoid all the panting and flickering while the tree is loading. it's ok for the user to have to wait a sec for the tree to load, so as long as they don't have to actually watch it load and all the flickering. is there a way to do this?
thanks!
|
|
|
|
|
In the normal TreeView class, you'd just call it's .BeginUpdate() and .EndUpdate() methods around the code where your clearing the date from the TreeView. I have no idea if the TreeListView your using exposes such methods. Double-buffering will NOT help your situation, simply because the TreeListView is redrawing itself after it removes/adds a node from/to the Tree.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Inside a tabpage I have a treeview docked to the left hand side from which the users drags treenodes onto a panel on the right. If the tree view is showing the vertical scrollbar then when dragging over the scrollbar slowly the drag and drap is being automatically cancelled
why ?
All help gratefully accepted
Thanks in advance
alan
|
|
|
|
|
hi, i need to save my GDI+ drawing and print them. for my save function i tried this but it saves as blank:
<br />
bt = new Bitmap (800,600);<br />
myGraphics = Graphics.FromImage(bt);<br />
<br />
private void saveImages()<br />
{<br />
SaveFileDialog saveFileDialog1 = new SaveFileDialog();<br />
saveFileDialog1.Title ="Save File";<br />
saveFileDialog1.Filter = "JPEG Images (*.jpg,*.jpeg)|*.jpg;*.jpeg|Gif Images (*.gif)|*.gif|Bitmaps (*.bmp)|*.bmp";<br />
if(bt != null)<br />
{<br />
if ((saveFileDialog1.ShowDialog() == DialogResult.OK))<br />
{<br />
string strFileName = saveFileDialog1.FileName;<br />
bt.Save(strFileName ,ImageFormat.Bmp);<br />
}<br />
}<br />
}
why is this so. and hw do i go about doing the print function?
Chris
|
|
|
|
|
Why would you expect there to be anything in your bitmap? You aren't drawing anything. If you think you are, then be sure to post all relevent code.
To print images, you use the System.Drawing.Printing namespace members, like PrintDocument . This will give you a Graphics object that you can use to draw your image (like Graphics.DrawImage ) to the print device.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
sorry.. here are my codes.
<br />
public class Graph : System.Windows.Forms.Form <br />
{<br />
public Bitmap bt;<br />
public Graphics myGraphics; <br />
<br />
public Graph()<br />
{<br />
bt = new Bitmap (800,600); <br />
myGraphics = Graphics.FromImage(bt);<br />
}<br />
<br />
protected override void OnPaint(PaintEventArgs e)<br />
{ <br />
base.OnPaint(e);<br />
DrawImage(e.Graphics);<br />
}<br />
private void DrawImage(Graphics myGraphics)<br />
{<br />
Pen myPen1 = new Pen (color.Blue,1);<br />
<br />
Point pt20 = new Point (20,30);<br />
Point pt21 = new Point (250,30); <br />
<br />
myGraphics.DrawLine (myPen1,pt20,pt21); <br />
}<br />
<br />
public Bitmap ReturnImage()
{<br />
DrawImage(myGraphics);<br />
return bt;<br />
}<br />
<br />
private void saveDrawing()<br />
{<br />
SaveFileDialog saveFileDialog1 = new SaveFileDialog();<br />
saveFileDialog1.Title ="Save File";<br />
saveFileDialog1.Filter = "JPEG Images (*.jpg,*.jpeg)|*.jpg;*.jpeg|Gif Images (*.gif)|*.gif|Bitmaps (*.bmp)|*.bmp";<br />
<br />
if(bt != null)<br />
{<br />
if ((saveFileDialog1.ShowDialog() == DialogResult.OK))<br />
{<br />
string strFileName = saveFileDialog1.FileName;<br />
bt.Save(strFileName ,ImageFormat.Bmp);<br />
}<br />
}<br />
else<br />
{<br />
MessageBox.Show("Blank bitmap");<br />
}<br />
<br />
}<br />
<br />
private void btnSave_Click(object sender, System.EventArgs e)<br />
{<br />
saveDrawing();<br />
}<br />
}<br />
}
thanks.
Chris
|
|
|
|
|
The first error that I noticed right away: never store your Graphics object. You either use the one passed to you in the PaintEventArgs from your OnPaint override, or create one for your control using Control.CreateGraphics (if you want a compatible bitmap on which to draw; having a compatible bitmap means the measurement units are the same, the scaling factors, etc., as the control itself). If you create a Graphics object for a Bitmap , at least use a bitmap that is the same size as the control.
In addition to not storing the Graphics , you shouldn't even store the Bitmap (factors can change; if the user changes the screen resolution or DPI settings, for example, your bitmap may not look right because GDI+ will now draw differently), and always dispose of objects like Graphics and Bitmap to make sure their native, unmanaged resources are freed immediately (they're unmanaged because the GC doesn't know about them and won't free them automatically like it does for managed objects). If not, that memory may remain allocated for some time until the GC gets around to finalizing (destroying) the object; and the only reason the native resources are freed is because the classes follow the disposable pattern (the finalizer disposes only unmanaged objects, while the IDisposable implementation disposes both unmanaged and managed objects immediately).
The code you should be using would be similar to the following:
class Graph : Form
{
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
DrawImage(e.Graphics);
}
private void DrawImage(Graphics g)
{
}
public Bitmap ReturnImage()
{
Bitmap bmp = new Bitmap(Width, Height);
using (Graphics g = Graphics.FromImage(bmp))
DrawImage(g);
return bmp;
}
void SaveDrawing()
{
using (SaveFileDialog dialog = new SaveFileDialog())
{
if (dialog.ShowDialog() == DialogResult.OK)
using (Bitmap bmp = ReturnImage())
bmp.Save(dialog.FileName, ImageFormat.Bmp);
}
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|