Ho una vista datagrid con stringhe HTML. Utilizzando un evento CellDoubleClick, sto visualizzando la stringa html in un controllo WebBrowser.Modifica HTML con un editor WYSIWYG
In Form1
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
try
{
if (e.ColumnIndex != 0 && e.RowIndex != -1)
{
string s = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
this.f2 = new Form2(s);
f2.ShowDialog();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
In Form2
private IHTMLDocument2 doc;
string reply;
public Form2(string reply)
{
InitializeComponent();
this.reply = reply;
}
private void Form2_Load(object sender, EventArgs e)
{
webBrowser1.DocumentText = reply; <--- string from DataGridView
IHTMLTxtRange range = doc.selection.createRange() as IHTMLTxtRange;
range.pasteHTML(webBrowser1.DocumentText);
range.collapse(false);
range.select();
doc = webBrowser1.Document.DomDocument as IHTMLDocument2;
doc.designMode = "On";
}
Utilizzando il codice di cui sopra, posso visualizzare correttamente la stringa HTML come un testo in chiaro, ma non sono in grado di modificarla. In alternativa, se utilizzo questo codice:
private IHTMLDocument2 doc;
private void Form2_Load(object sender, EventArgs e)
{
webBrowser1.DocumentText = reply; <--- string from DataGridView
doc = webBrowser1.Document.DomDocument as IHTMLDocument2;
doc.designMode = "On";
IHTMLTxtRange range = doc.selection.createRange() as IHTMLTxtRange;
range.pasteHTML(webBrowser1.DocumentText);
range.collapse(false);
range.select();
}
Sarà un modulo vuoto, ma potrò scrivervi.
Ho la sensazione che abbia a che fare con range.pasteHTML(webBrowser1.DocumentText);
nel metodo Form2_Load, ma non conosco nessun altro metodo che mi consenta di visualizzare la stringa HTML da DataGridView all'apertura di Form2.
Desidero consentire agli utenti di modificare la stringa HTML come testo normale (dopo di che verrà convertita in HTML e visualizzata nella vista datagrid).