DataGridView and Encoding

R

Rainer Queck

Hi NG,

is it possible, and if yes how, to change the encoding of a datagridview?
I am loading a csv file to a dgv using a certain Encoding, but there are
columns using different encoding like cyrill.
I would now like to switch the encoding at runtime, without the need to
reload the file with a different encoding.

Thanks for help and hints
Rainer Queck
 
J

Jon Skeet [C# MVP]

Rainer Queck said:
is it possible, and if yes how, to change the encoding of a datagridview?
I am loading a csv file to a dgv using a certain Encoding, but there are
columns using different encoding like cyrill.

DataGridView itself doesn't have any encoding associated with it - by
the time the CSV file has been loaded into the view, everything will be
in Unicode.

Are you certain that the CSV file is using different encodings for
different columns? That sounds utterly mad to me. I suspect you'll have
to write a custom class to load the CSV into the DataGridView. If you
could avoid being in such a horrible situation to start with, it would
be a lot better though.
 
L

Linda Liu [MSFT]

Hi Rainer,

Could you tell me how you load a csv file to a DataGridView? You load it by
yourself, or via a 3rd party class?
I am loading a csv file to a dgv using a certain Encoding, but there are
columns using different encoding like cyrill.

I am sorry that I couldn't understand what you mean in the above sentence.
Could you please explain it more?

To make things clearer, you may send me your sample project that could just
reproduce the problem. To get my actual email address, remove 'online' from
my displayed email address.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Rainer Queck

Hi Jon,
DataGridView itself doesn't have any encoding associated with it - by
the time the CSV file has been loaded into the view, everything will be
in Unicode.

Are you certain that the CSV file is using different encodings for
different columns? That sounds utterly mad to me. I suspect you'll have
to write a custom class to load the CSV into the DataGridView. If you
could avoid being in such a horrible situation to start with, it would
be a lot better though.
True, but life is as it is ;-)
I have no influence on how the csv is built, also what columns have which
coding.
Here is a typical line out of one of the csv files (I hope it show on your
screen as it does here):

;Modify Cap Layout;Èçìåíèòü ðàñêðîé ëèñòà;Traverenzuschnitt ändern;;Ïðîìÿíà
íàäëúæíî ðÿçàíå;

Only the "end-user" of my app knows what to expect, this is why I must give
him the posibillity to select the coding.

I think with my dgv I will do the online recoding with a "string ->
byte[] -> string method."

Regards
Rainer
 
R

Rainer Queck

Hi Linda,

Linda Liu said:
Hi Rainer,

Could you tell me how you load a csv file to a DataGridView? You load it
by
yourself, or via a 3rd party class?
I have written me a littel helper class to do load the csv file to a
DataTable with then is the DataSource of my dgv.
I am sorry that I couldn't understand what you mean in the above sentence.
Could you please explain it more?
I have no influence on how the csv is built, also what columns have which
coding.
Here is a typical line out of one of the csv files (I hope it show on your
screen as it does here):

;Modify Cap Layout;Èçìåíèòü ðàñêðîé ëèñòà;Traverenzuschnitt ändern;;Ïðîìÿíà
íàäëúæíî ðÿçàíå;

Only the "end-user" of my app knows what to expect, this is why I must give
him the posibillity to select the coding.
To make things clearer, you may send me your sample project that could
just
reproduce the problem. To get my actual email address, remove 'online'
from
my displayed email address.
Thank you for your offer.
I think I can solve my dgv problem by recoding with a "string -> byte[] ->
string" method which I will start do code now.

Regards
Rainer
 
J

Jon Skeet [C# MVP]

True, but life is as it is ;-)
I have no influence on how the csv is built, also what columns have which
coding.
Here is a typical line out of one of the csv files (I hope it show on your
screen as it does here):

;Modify Cap Layout;Èçìåíèòü ðàñêðîé ëèñòà;Traverenzuschnitt ändern;;Ïðîìÿíà
íàäëúæíî ðÿçàíå;

Well, that shows a bunch of random characters with some ASCII in there
as well. There's no indication of which columns are in which encoding.
Only the "end-user" of my app knows what to expect, this is why I must give
him the posibillity to select the coding.

I think with my dgv I will do the online recoding with a "string ->
byte[] -> string method."

That's extremely dangerous, and almost certainly won't work - it
assumes that you can get back the original bytes from the decoded
string, which assumes the original binary data is valid text in
whatever encoding you read the whole file in.

You might want to think about having your own wrapper which streams
the CSV in, changing the column encodings as it goes.

Jon
 
L

Linda Liu [MSFT]

Hi Rainer,

Thank you for your response.

How about your problem now?

If you need our assistance, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support
 
R

Rainer Queck

Hi Linda,

thanks for checking back on me.
How about your problem now?
For the moment, the online decoding went into the background (not needed for
the moment :)

Regards
Rainer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top