H
hajduk_25
Hi,
my problem was already posted here in a similar manner, but I didn't
find a convincing solution for it yet. It's about the following: I use
in C# a DataGridView for displaying data, and one of the columns is a
byte array (it's a tinyblob in MySQL, I use it for simulating GUIDs in
MySQL, but this doesnt't matter). In the DataGridView this is always
shown as Byte[]-Array. One idea to solve this was to handle it in the
CellFormattingEvent like this:
private void DataGridContent_CellFormatting(object sender,
System.Windows.Forms.DataGridViewCellFormattingEventArgs e){
e.Value = bytearray_to_string((byte[])e.Value);
}
(bytearray_to_string is a method for converting a byte array into a
string)
This try led to a DataError, because e expected a byte array and not a
string as value. Then I tried to change the ValueType of the
DataGridView by inserting the codeline
((DataGridView)sender).Columns[e.ColumnIndex].ValueType =
typeof(string);
in the above code fragment. Surprisingly it was possible to change the
ValueType (I'd expected an error a la "changing ValueType is not
possible while the DataGridView contains data"), but the same error
occured again.
The latest try was to handle it via DataBinding:
Binding bi = new Binding("Text", Dt, "bytearraycolumn");
bi.Parse += new ConvertEventHandler(bi_Parse);
bi.Format += new ConvertEventHandler(bi_Format);
(Dt is the DataTable containing the data, the Parse and Format methods
convert byte arrays to strings and vice versa)
Unfortunally, the result was similar to the previous...
Has anybody an idea how to do this right?
Greetings from Germany
Hajduk
my problem was already posted here in a similar manner, but I didn't
find a convincing solution for it yet. It's about the following: I use
in C# a DataGridView for displaying data, and one of the columns is a
byte array (it's a tinyblob in MySQL, I use it for simulating GUIDs in
MySQL, but this doesnt't matter). In the DataGridView this is always
shown as Byte[]-Array. One idea to solve this was to handle it in the
CellFormattingEvent like this:
private void DataGridContent_CellFormatting(object sender,
System.Windows.Forms.DataGridViewCellFormattingEventArgs e){
e.Value = bytearray_to_string((byte[])e.Value);
}
(bytearray_to_string is a method for converting a byte array into a
string)
This try led to a DataError, because e expected a byte array and not a
string as value. Then I tried to change the ValueType of the
DataGridView by inserting the codeline
((DataGridView)sender).Columns[e.ColumnIndex].ValueType =
typeof(string);
in the above code fragment. Surprisingly it was possible to change the
ValueType (I'd expected an error a la "changing ValueType is not
possible while the DataGridView contains data"), but the same error
occured again.
The latest try was to handle it via DataBinding:
Binding bi = new Binding("Text", Dt, "bytearraycolumn");
bi.Parse += new ConvertEventHandler(bi_Parse);
bi.Format += new ConvertEventHandler(bi_Format);
(Dt is the DataTable containing the data, the Parse and Format methods
convert byte arrays to strings and vice versa)
Unfortunally, the result was similar to the previous...
Has anybody an idea how to do this right?
Greetings from Germany
Hajduk