사용자 지정 DataGridViewButtonCell을 만들어 클릭 한 번 파일을 다운로드하려고합니다. 이 클래스는 완벽하게 작동하지만 rows.add() 메서드를 사용할 때 DataGridView에 추가되지 않습니다. 레이블에 ToString() 메서드를 사용하고 CellTemplate에서 고유 한 메서드를 만드는 것처럼 보입니다.C# DataGridView 추가 ToString()을 사용합니까?
특정 열의 형식은 DataGridViewDownloadColumn입니다. 또한 격자보기에있는 값을 출력하는 테스트를 실행했으며 올바른 클래스가 인스턴스화되었습니다.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using MS.Internal.Xml;
using System.Net;
namespace RSS_Catcher
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
XmlReader objReader = XmlReader.Create("http://revision3.com/filmriot/feed/Xvid-Large");
while (objReader.ReadToFollowing("enclosure"))
{
objReader.MoveToFirstAttribute();
Uri objURI = new Uri(objReader.ReadContentAsString());
string[] objString = objURI.Segments;
DownloadButton objDL = new DownloadButton(objURI, objString[objString.Length - 1]);
this.dataGridView1.Rows.Add(false, "Hello!", objDL);
}
}
}
public class DataGridViewDownloadColumn : DataGridViewButtonColumn
{
public DataGridViewDownloadColumn()
{
CellTemplate = new DownloadButton();
}
}
class DownloadButton : DataGridViewButtonCell
{
WebClient objDownloader = new WebClient();
Uri fileURL;
string strSavePath;
public DownloadButton()
{
}
public DownloadButton(Uri fileURI, string strFilename) : base()
{
objDownloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgChanged);
this.fileURL = fileURI;
this.strSavePath = strFilename;
this.Value = "Download";
}
protected override void OnClick(DataGridViewCellEventArgs e)
{
// If it's downloading, cancel the download
if (objDownloader.IsBusy)
{
objDownloader.CancelAsync();
this.Value = "Download";
}
else
objDownloader.DownloadFileAsync(fileURL, strSavePath);
base.OnClick(e);
}
void ProgChanged(object sender, DownloadProgressChangedEventArgs e)
{
this.Value = e.ProgressPercentage + "%";
}
public override string ToString()
{
return
"Download Button:\n" +
this.fileURL.ToString();
}
}
}
나는 시간이 쓰레기 싸우고했습니다
다음은 레이아웃 정보없이 내 코드입니다. 어떤 도움을 주셔서 감사합니다.