|
You can use something like this.
public class AvoidWindowHandleErrorForm : Form
{
private bool _hasHandle = false;
public AvoidWindowHandleErrorForm()
{
this.HandleCreated += delegate
{
_hasHandle = true;
};
}
public new void Invoke(Delegate d)
{
if (this._hasHandle)
base.Invoke(d);
else
{
this.HandleCreated += delegate
{
base.Invoke(d);
};
}
}
}
If I remember correctly, there are a couple of ways to force handle creation, though I forgot which ones :s.
Standards are great! Everybody should have one!
|
|
|
|
|
Hello fellow coders.
I'm having a hard time figuring out very easy thing with the datagridview so here is a screen of it in my program:
datagrid
My 2 questions are, I think, easy, but I can't find any solution and Google isnt helping me at all:
- How to get ride of the left column (the one with the cursor that shows the selected rows), or at least, how to resize it to make it a fixed size ?
- How to make column headers clickable? Currently in my program, the columns are not clickable and this is quite a huge issue for sorting things out. That followed with a 2nd question: how to programatically display a sorting glyph to the column header?
Thank you!
|
|
|
|
|
Tony_P wrote: - How to get ride of the left column (the one with the cursor that shows the selected rows), or at least, how to resize it to make it a fixed size ?
set RowHeadersVisible property to false, and to resize it, DGV have a property named RowHeadersWidth
Tony_P wrote: How to make column headers clickable? Currently in my program, the columns are not clickable
what you wanna say ?? default is clickable
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
set RowHeadersVisible property to false, and to resize it, DGV have a property named RowHeadersWidth
Thank you!
what you wanna say ?? default is clickable
Well I'm feeding my datagridview with a SqlCeResultSet (through a BindingSource) and autogeneratecolumns set to true so I guess everything is default but still the column headers are not clickable. They are like standard labels.
SqlCeResultSet rs = functionThatReturnsAResultSet();<br />
this.dataGridView1.AutoGenerateColumns = true;<br />
this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;<br />
this.bindingSource1.DataSource = rs;<br />
this.dataGridView1.DataSource = this.bindingSource1;
I confirm column headers are not clickable.
|
|
|
|
|
try this :
DGV.Columns[0].SortMode = DataGridViewColumnSortMode.Automatic;
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Still no difference. I'm investigating on it but I can't find any help. Could this be a problem with SqlCeResultSet or the fact that I have an "ORDER BY" statement in my SQL query giving the ResultSet?
|
|
|
|
|
i think its cause is binding, you have bound the DGV
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I see. I've tryed to recreate a new DGV and fill it with a simple "SELECT * FROM" query but still got the same results. Is there any way to make the column clickable even though data is bound (so I could handle the "ColumnClick" events) ?
In fact, I've tried to add a HeaderMouseClick event to my DGV and it's handled properly, but still the headers don't act like they're clickable (ie: they act like labels, not buttons).
|
|
|
|
|
dunno , i will suggest you to add rows manually
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
i want to make a remote backup server using C#. so if any body has code examples related to this plz send me.
regards
|
|
|
|
|
Read the first post in the forum titled "how to get an answer to your question", pay attention to item #2
led mike
|
|
|
|
|
hi friends...
In my form contain one richtextbox and one button.. in richtextbox i want to show the contents page by page or some fixed length from rtf file while clicking the button...How can i do this...
|
|
|
|
|
This question is asked one or more times a week. There is an article here on code project that covers working with RichTextBox, go find it.
led mike
|
|
|
|
|
i am tried but i can't found correct document...You have any link please send me..
|
|
|
|
|
Hi all,
Could someone please explain to me why the following code doesnt work?
<code>
Rectangle r = new Rectangle(0, 0, 100, 100);
Pen p = Pens.Black;
private void Form1_Load(object sender, EventArgs e)
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint,true);
//a.AddLine(new Point(10, 10), new Point(100, 10));
}
protected override void OnMouseMove(MouseEventArgs e)
{
//Invalidate old location
Invalidate(r);
r.Location = e.Location;
//Invalidate new location
Invalidate(r);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
//Clear clipping rect
e.Graphics.FillRectangle(Brushes.White, r);
//Draw invalidated region
e.Graphics.DrawRectangle(p, r); //Method will draw the right and bottom side out of clipping rect
}</code>
When i run it, the rectangles bottom and right hand side are drawn outside the clipping rectangle. I thought that if something was drawn outside the clipping rectangle, it would be discarded. However this doesnt seem to be the case here.
when i move the mouse, I move the rectangles location also. Before i change the location of the rect, i invalidate it, and then invalidate again once change has been made.
In the drawing routine i wipe the clipping rect with background colour, but for some reason artifacts ouside the clipping area remain.
The end result of the mouse move is an artifact trail, similar to a mouse trail and exactly like what happens, when you win at ms solitare.
It would appear that im not invalidating the right area, but i dont understand why!
I have done a fair bit of graphics programming before, and have never experienced any problem like this. If im invalidating the old bounds before changing them for the new bounds, it should be removing the old screen.
If i change the drawing code to make sure that the rectangle is drawn inside the clipping rect, the problem doesnt happen.
But I just cant understand why the problem occurs anyway. Surely invalidate should cause the overlapping line to be removed?
Here is the code that has been modified not to overdraw the clipping region:
<code>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
//Clear clipping rect
e.Graphics.FillRectangle(Brushes.White, r);
Rectangle r2 = r;
r2.Height -= 1;
r2.Width -= 1;
//Draw invalidated region
e.Graphics.DrawRectangle(p, r2); //Method will draw the right and bottom side out of clipping rect
}</code>
I would be most grateful to anyone that could point me in the right direction, or tell me if im doing something stupid.
Many thanks,
chris.
Thanks for your help!
<div class="ForumMod">modified on Tuesday, March 25, 2008 11:47 AM</div>
|
|
|
|
|
Without running your code, I'm thinking the problem is here:
protected override void OnMouseMove(MouseEventArgs e)
{
Invalidate(r);
r.Location = e.Location;
Invalidate(r);
}
The first call to Invalidate(r) fills the rectangle then draws it. You then move the rectangle and call Invalidate(r) again which fills the relocated rectangle and then draws it - however, there is no code that is repainting over the old rectangle. You need to keep track of the area that was under the original rectangle and invalidate the union of the old rectangle and the new one (you will only need to call invaldiate once in OnMouseMove when you do this). Also, the call to e.Graphics.FillRectangle(Brushes.White, r) in the OnPaint method will need to be adjusted to fill the clip region (can't remember the property name off hand, but should be easy enough to find).
-----
In the land of the blind, the one eyed man is king.
|
|
|
|
|
Thanks very much for replying.
"Also, the call to e.Graphics.FillRectangle(Brushes.White, r) in the OnPaint method will need to be adjusted to fill the clip region (can't remember the property name off hand, but should be easy enough to find)."
Yeah i realised i had done that! r instead of e.ClipRectangle property, but it doesnt actually make any difference any way.
"You need to keep track of the area that was under the original rectangle and invalidate the union of the old rectangle and the new one.."
Thats what the first invalidate does! When you call invalidate, it wont invalidate immediately. If you were to call refresh() then it would go straight to the paint code, but this way it just carries on executing the next instruction.
I then set the new location and invalidate this as well. this way both the old and new rects are included in the clipping rect, which is filled in the Paint routine (with the corrected code).
---------------------------
Chris.
|
|
|
|
|
Herbertmunch wrote: Thats what the first invalidate does! When you call invalidate, it wont invalidate immediately. If you were to call refresh() then it would go straight to the paint code, but this way it just carries on executing the next instruction.
Yep, you're right - it's been a while since I've done much with GDI apparently, and I forgot that. However, Refresh is a bit more heavy handed - it will invalidate everything then force a redraw - if you only want to force the redraw the invalidated regions, use the Update method. Not that this matters to the issue at hand ...
Anyway, I loaded this up in a test project just to see what was going on - I should have done this right away but was too lazy Anyway, it looks like what you're seeing is from the draw rectangle actually drawing one pixel past the edge of the rectangle (you can see this easier if you make the rectangle width to be 1, you'll see a two pixel wide line drawn). What you'll want to do is just to invalidate an area slightly larger than your rectangle - so your both of your invalidates should so something like: Invalidate(Rectangle.Inflate(r, 2, 2)) . Then, assuming your paint has been updated to fill the clip region, all is working correctly.
The reason you need to invalidate an area larger than the rectangle on the second invalidate as well as the first is becauase of the same issue - the pen draws one pixel to the right and one down from the actual rectangle, causing the rectangle to be clipped if moving to the right or down.
-----
In the land of the blind, the one eyed man is king.
|
|
|
|
|
thanks
"
What you'll want to do is just to invalidate an area slightly larger than your rectangle.."
I came to the same conclusion, but its just a bit nasty for my liking!
I cant remember ever encountering this problem before, which is strange.
it makes no sense at all why this occurs. Surely nothing should be displayed in an area that hasnt been invalidated. Why is this 1 pixel wide artifact occuring? Is this a bug with GDI+?
---------------------------
Chris.
|
|
|
|
|
DataTable dtDetails = new DataTable();//build datatable...
//add columns...
dtDetails.Columns.Add("Cusip");
dtDetails.Columns.Add("Isin");
dtDetails.Columns.Add("Position");
dtDetails.Columns.Add("Bond Price");
//add rows...
dtDetails.Rows.Add("cusip value");
How do I add rows to the datatable with values in each cell in the appropriate row for the column?
For example; the above code creates a datatable with columns and a row. In the first column of the row it shows "cusip value". I also want to add other texts to other cells for other columns in that row.
How is this done please?
Thanks
|
|
|
|
|
try this :
DataRow Dr = dtDetails.NewRow();
Dr["Position"] = ???
Dr["Isin"] = ???
Dr["Bond Price"] = ???
Dr["Cusip"] = ???
dtDetails.Rows.Add(Dr);
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Thanks
modified on Tuesday, March 25, 2008 12:05 PM
|
|
|
|
|
I have a ListView, and I'd like to only allow a single range to be selected. I need the equivalent of Java's SINGLE_SELECTION_INTERVAL ( http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/ListSelectionModel.html#SINGLE_INTERVAL_SELECTION ). For example:
If a ListView has 5 rows, #1,#2 could be selected, or #3,#4,#5, or just #3, but not #1,#3,#4.
Is there any way of adding this functionality in C# without getting heavily into rewriting the control?
|
|
|
|
|
i dont think so, you have to write code for this purpose
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I have a file. I want found the process/handle by which my file is opened?
Ambarish Jana
|
|
|
|
|