|
Hi,
Inverso1 wrote: using (TextReader reader = new StreamReader(filename,true))
AFAIK a text stream constructor without explicit encoding will:
1. look for a byte order mask indicating the stream holds Unicode/UTF8 characters
2. lacking that, assume it is an 8-bit encoding corresponding to the thread's CultureInfo which defaults to your system's default "code page", which would be e.g. 1252 in Western Europe.
As you said 155 would be "single right-pointing angle quotation mark" in standard ANSI (see e.g. here[^]). And it should work well if your system or your thread were set to ANSI.
It also maps OK in Windows code page 1252 (see here[^]). But it wouldn't in many others.
I suspect your system/app is not using a code page that interprets 155 as "single right-pointing angle quotation mark".
I suggest:
1. you have a look at the file using Notepad
2. you check your code page (I don't know how by heart!)
3. you explicitly set the encoding when opening the stream, assuming you know it to be constant.
And of course you'll risk getting in trouble again when dealing with 8-bit text files from different origins, that was after all the reason they invented Unicode.
|
|
|
|
|
Hey Luc,
thanks for your response; adding the encoding fixed the issue. I am a little worried about the possibility of other codepages, since the idea is that this system can take data from any source. Guess I'll have to configure it to allow different data sources (i.e. file locations) to have a custom codepage specified.
For people following this thread, you may be interested in the code below, which gives the systems' default codepage (as Luc mentioned, for me it's 1252).
Console.WriteLine(Encoding.Default.CodePage.ToString());
I've now modified one line of my code to read as follows, which seems to have fixed the issue:
using (TextReader reader = new StreamReader(filename,Encoding.Default,true))
It seems a bit strange that the system's not using the default by default, but hey, all's good. I've also tried chucking UTF-8 and UTF-16 formatted text documents through and these were also encoded correctly.
Thanks again,
JB
|
|
|
|
|
I noticed a weird behaviour in ListView . When its MultiSelect property is set to true and I press a mouse button while the cursor is inside the control, I get a MouseDown event. Then I release the button and get a MouseUp event, just as I would expect. However, when I set the MultiSelect property to false and press a mouse button, I suddenly get the MouseUp event immediately after the MouseDown one. When I then actually release the button, no MouseUp fires. Is this intentional? How can I then properly determine when the mouse button was actually released?
|
|
|
|
|
Can you check the control's MultiSelect property in your mouse event handlers?
/ravi
|
|
|
|
|
I can confirm what you are experiencing - this only occurs when the control itself is clicked. When a ListViewItem is clicked (MouseDown ) the behaviour is normal (even if the mouse is moved away from the clicked item).
Very odd.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Yes, that's true, unfortunately I need to properly handle all clicks in the control, not just those on a ListViewItem . It even doesn't work on a ListViewSubItem .
|
|
|
|
|
It works on sub items if you set FullRowSelect to true... wired bahavior...
|
|
|
|
|
This is a semi-solution.
Subclassing the ListView and overriding WndProc , listen for the left mouse button up message and raise the MouseUp event passing the correct parameters.
With a bit more work you may be able to use a flag to allow/disallow MouseUp messages to supress the erroneous one that you are getting.
public class FixedListView : ListView
{
private const int WM_LBUTTONUP = 0x0202;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_LBUTTONUP)
{
Point point = new Point(((int)m.LParam) & 0x0000FFFF, (int)m.LParam >> 16);
OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, point.X, point.Y, 0));
return;
}
base.WndProc(ref m);
}
}
WM_LBUTTONUP Message[^]
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Thanks for the proposed semi-solution. I put together different pieces and came up with this solution which seems to do what I want First, I leave the MultiSelect property set to false and set FullRowSelect to true . Then I use this code:
public class CustomListView : ListView
{
public CustomListView()
{
InitializeComponent();
}
bool fakeMouseUp = false;
bool mouseDownOnItem = false;
protected override void OnMouseDown( MouseEventArgs e )
{
mouseDownOnItem = HitTest( e.Location ).Item != null;
Debug.WriteLine( "OnMouseDown" );
base.OnMouseDown( e );
}
protected override void OnMouseUp( MouseEventArgs e )
{
if( mouseDownOnItem || fakeMouseUp )
{
Debug.WriteLine( "OnMouseUp" );
mouseDownOnItem = false;
fakeMouseUp = false;
base.OnMouseUp( e );
}
}
protected override void WndProc( ref Message m )
{
if( !mouseDownOnItem && m.Msg == 0x0202 )
{
fakeMouseUp = true;
Point point = new Point( ((int) m.LParam) & 0x0000FFFF, (int) m.LParam >> 16 );
OnMouseUp( new MouseEventArgs( MouseButtons.Left, 1, point.X, point.Y, 0 ) );
}
base.WndProc( ref m );
}
}
But I always have a feeling of wasted time when I need to do such workarounds for weird .NET behaviour. Why on Earth do I get a MouseUp event when the mouse button was not physically released?
|
|
|
|
|
Hello
I need help in editing a datagridview's row.
I have a grid which is dynamically populated in a way that user adds some data in the form of rows.
Now, I want to give the user the option to edit the row as well. I want to provide the functionality just like asp.net's editable gridview. that is, i want that when a user click on a cell to edit it, a dropdown should be displayed containing selected values. I also want that user may have a cell with text 'edit' and user should click that to start editing the row. as soon as the user click the 'edit', the text should be changed to 'update'.
Please guide me for it.
saq!b
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
Look into DataGridViewComboBoxColumn and DataGridViewButton column. That must suite your needs.
|
|
|
|
|
thanks danish.
i was just looking into DataGridViewComboBoxColumn. please tell me if it is possible to change the column type of a row at runtime?
saq!b
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
Set the DisplayStyle property to nothing for the combobox column. HTH.
|
|
|
|
|
can you write the syntax here plz?
saq!b
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
Hi,
Go through this code........
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False"
BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px"
CellPadding="4" CellSpacing="2" ForeColor="Black" Height="285px"
onrowcancelingedit="gv_RowCancelingEdit" onrowdeleting="gv_RowDeleting"
onrowediting="gv_RowEditing" onrowupdating="gv_RowUpdating" Width="493px">
<FooterStyle BackColor="#CCCCCC" />
<RowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Item Name" />
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="lblHead" runat="server" Text="Price"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPrice" runat="server" Text='<%#Eval("Price")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl1" runat="server">
<asp:ListItem>1000</asp:ListItem>
<asp:ListItem>2000</asp:ListItem>
<asp:ListItem>3000</asp:ListItem>
<asp:ListItem>4000</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:ButtonField DataTextField="Description" HeaderText="Desription" />
<asp:CommandField ShowCancelButton="true" ShowDeleteButton="true" ShowEditButton="true" />
</Columns>
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
</asp:GridView>
|
|
|
|
|
i found a solution for invalidoperation in net , force handle to create. but i get the exception still.
let me explain the situation
in Form A ,in the constructor i call a method named startmodule(), in this method it invokes a static delegate that is in From A ,from a separate thread. so in the Form A constructor i called this.handle
as the first step, but still i get the exception any idea about what is wrong..!
thanx in advance.
|
|
|
|
|
While inside a Form constructor, the Form does not yet exist. Can't you postpone your failing stuff to some later point, say the Load event or even maybe the Shown event?
|
|
|
|
|
I would recommend moving the call to startmodule() out of the constructor and into the form's OnLoad() method. Do you work after the base.OnLoad() call, and I expect you'll find things work properly.
|
|
|
|
|
I don't know if this is relevant to your situation (but you may find it useful sometime even if not), you can force the handle to be valid inside a constructor by getting the value of the Handle property i.e.
public FormA()
{
IntPtr handle = Handle;
}
More info here[^].
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
modified on Tuesday, August 24, 2010 3:37 PM
|
|
|
|
|
Hi,
I have some collection that hold some struct.
Its look like this :
struct PointColor
{
Point p;
Color c;
public PointColor(Int32 x, Int32 y, Color c)
{
p = new Point( x, y );
this.c = c;
}
};
private List<PointColor> PointColorCollection = new List<PointColor>();
My Question is:
Because the object in the collection are value type - does this collection cleaning can cause somehow the GC to run ?
If the answer is 'Yes' - is there some way to optimize this code and avoid GC to run ?
Thanks.
|
|
|
|
|
Do yourself a favor, and just don't worry about it. The garbage collector works beautifully in almost all situations. As long as you keep a reference to it, no matter how indirect, it won't be trashed. Whether it's a class or struct doesn't really matter.
|
|
|
|
|
It's next question about manipulating GC in last few days... Sometimes I have the feeling, that some people think, that if they force GC to work they are better developers... What for? If application uses to much memory it's probably your fault, not the GC not working properly.
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
There seems to be some kind of wide spread incomfort (lacking a better term in the moment) with this basic concept of CLR. What I see is a lot of folks who are simply told "tommorrow, you start writing .NET code"... So they do start applying the 'learning by doing' method...
|
|
|
|
|
Yanshof wrote: does this collection cleaning can cause somehow the GC to run ?
No.
However not the no you are hoping for: the GC will run when you either force it to run (say calling GC.Collect, a bad idea) or when you do something (typically execute a new Something) that needs more memory than is currently available. Freeing/clearing something will not cause the GC to run (except when you would be extremely nasty and have objects that allocate new stuff in their finalizer, a horrible thought it is).
I think you have been asking the wrong question. Either you are worried about performace or you already are having performance trouble. Then you should give more contextual information and ask a more open question.
The code shown basically represents a pixel; I do hope you are not using that to construct an entire image.
|
|
|
|
|
I don't understand your questions... First you ask if "cleaning" a collection causes GC to run. - Answer is Maybe... Because GC is hardly predictable and depends on the memory use of your whole application. You can force garbage collection with GC.Collect - but this is not good practice...
Then you say you want to avoid GC to run? And what the hell you mean with "because the objects in the collection are value types"?
Maybe you tell us what your problem is? Performance, memory, general interest? How many values will be in the collection and what you mean with "cleaning"?
|
|
|
|