Windows Develop Bookmark and Share   
 index > Windows Forms General > Is it posible to copy the GridView data from the WebBrowser1 to the clipbord
 

Is it posible to copy the GridView data from the WebBrowser1 to the clipbord

Hi there is there a way to copy GridView data to the clip board in winform app,
i have form1 on it a have a WebBrowser1 wich displys thee datagrid, i need a button that can copy the data in the gridview.


olso can i populate the textboxes inside the WebBrowser1 with defoult values.

thanks
deti  Friday, September 18, 2009 9:57 AM
With your grid element id you can get the data you wantby outerhtml or outertext properties of HtmlElement.

Here is a sample code:

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElement elm = webBrowser1.Document.GetElementById("ctl00_ContentPlaceHolder1_wgrFoodAverage_ctl01");
Clipboard.Clear();
Clipboard.SetText(elm.OuterHtml);

}

  • Marked As Answer bydeti Friday, September 18, 2009 3:33 PM
  •  
Tamer Oz  Friday, September 18, 2009 2:00 PM
yes of course you can do this.

You must ensure that document load is completed before setting values.

Here is the code.

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

{

webBrowser1.Document.GetElementById(

"sb_form_q").SetAttribute("value", "foo");

webBrowser1.Document.GetElementById(

"sb_form_go").InvokeMember("click");

}

  • Marked As Answer bydeti Friday, September 18, 2009 3:33 PM
  •  
Tamer Oz  Friday, September 18, 2009 3:28 PM

Not a very efficient way but I hope this works

void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

{

foreach (HtmlElement he in wb.Document.All)

{

if (he.GetAttribute("value") == "foo")

{

MessageBox.Show("found");

}

}

}

  • Marked As Answer bydeti Monday, September 21, 2009 3:57 PM
  •  
Tamer Oz  Friday, September 18, 2009 4:01 PM
i dont know if there is any easy method to copy data grid contents to clip board but you can try some what like this


Clipboard.Clear();
for(int i=0;i<dataGridView1.RowCount;i++)
{
for(int j=0;j<dataGridView1.ColumnCount;j++)
{
Clipboard.SetText(Clipboard.GetText()+"\t\t "+dataGridView1[j,i].Value);
}
Clipboard.SetText(Clipboard.GetText()+"\r\n");
}



and for textbox problem


this.<textboxname>.Text=<defaultvalue>;
Bharath kumar Y.S  Friday, September 18, 2009 10:53 AM

The textbox and the GridView are html controls they are displayd in a WebBrowser1 winform control so i am trying to copy from an html page

deti  Friday, September 18, 2009 11:17 AM
With your grid element id you can get the data you wantby outerhtml or outertext properties of HtmlElement.

Here is a sample code:

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElement elm = webBrowser1.Document.GetElementById("ctl00_ContentPlaceHolder1_wgrFoodAverage_ctl01");
Clipboard.Clear();
Clipboard.SetText(elm.OuterHtml);

}

  • Marked As Answer bydeti Friday, September 18, 2009 3:33 PM
  •  
Tamer Oz  Friday, September 18, 2009 2:00 PM

Hi Tamer i tryed your code and nothig happend, the Clipboard is not cleared and no new data copied,

Is this the table name in html?
("ctl00_ContentPlaceHolder1_wgrFoodAverage_ctl01");

How can i call it from a buttonclick?



Ok I put it under WebBrowser1_FileDownload and it cleard the Clipboard but did not copy any data
deti  Friday, September 18, 2009 2:42 PM
Ok it is working but is no good to me cos the Id is dynamic so i cant get a fis on it,

Wat about assignin defaylt values to textboxes,

can i do something like this:

Dim elm As HtmlElement = WebBrowser1.Document.GetElementById("loginUserName")

elm =

"test"

deti  Friday, September 18, 2009 3:21 PM
yes of course you can do this.

You must ensure that document load is completed before setting values.

Here is the code.

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

{

webBrowser1.Document.GetElementById(

"sb_form_q").SetAttribute("value", "foo");

webBrowser1.Document.GetElementById(

"sb_form_go").InvokeMember("click");

}

  • Marked As Answer bydeti Friday, September 18, 2009 3:33 PM
  •  
Tamer Oz  Friday, September 18, 2009 3:28 PM
Thanks ,


is there a way to get

webBrowser1.Document.GetElementByValue(?

deti  Friday, September 18, 2009 3:53 PM

Not a very efficient way but I hope this works

void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

{

foreach (HtmlElement he in wb.Document.All)

{

if (he.GetAttribute("value") == "foo")

{

MessageBox.Show("found");

}

}

}

  • Marked As Answer bydeti Monday, September 21, 2009 3:57 PM
  •  
Tamer Oz  Friday, September 18, 2009 4:01 PM
it worked thanks


deti  Monday, September 21, 2009 3:57 PM
I had a problem with using the WebBrowser1 with popups it prompts me to login again, so i used :Shell("explorer.exe http:\\yahoo.com,")

can i use the same for exploree.exe? Like:

private void Explorer.exe_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

{

Explorer.exe.Document.GetElementById(

"sb_form_q").SetAttribute("value", "foo");

Explorer.exe.Document.GetElementById(

"sb_form_go").InvokeMember("click");

}

is there such event?

deti  Thursday, September 24, 2009 10:06 AM

You can use google to search for other answers

Custom Search

More Threads

• Making the <A NAME="..."> tag work with the WebBrowser
• Multiselect view in the listbox
• basic forms question
• Windows Messages
• select value in listbox please help urgent
• VB-APP: Reset the combobox text display to blank?
• how to disable this button?
• User Control Inheritance and a GroupBox in the derived class.
• Memory Leak with WinForms Control
• How to Stop Hiding Menu Items?