|
|
|
C# WinApp DataGridViewLinkCell หรือ DataGridViewTextboxCell ก็ได้ อยากแยกรับข้อความจาก SQL ครับ |
|
|
|
|
|
|
|
ก็เก็บอีก Colum ไว้เป็น Path เต็มๆ ครับ พอเวลากเเลือก ก็แค่ไปดึงค่าจาก COlumn ที่เก็บพาธเต็มๆ ไปใช้งาน
|
|
|
|
|
Date :
2018-01-26 15:26:28 |
By :
OOP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
LoadData();
}
public void LoadData() {
var listFile = System.IO.Directory.GetFiles(@"c:\windows").Select(s => new {
FilePath = s ,
FileName = System.IO.Path.GetFileName(s)
}).ToList();
var colFilePath = new DataGridViewTextBoxColumn();
colFilePath.DataPropertyName = "FilePath";
colFilePath.HeaderText = "FilePath";
var colFileName = new DataGridViewTextBoxColumn();
colFileName.DataPropertyName = "FileName";
colFileName.HeaderText = "FileName";
var colCustom = new customCol();
colCustom.DataPropertyName = "FilePath";
colCustom.HeaderText = "CustomFilePath";
colCustom.Width = 500;
dgv1.AutoGenerateColumns = false;
dgv1.Columns.AddRange(colFileName, colFilePath, colCustom);
dgv1.DataSource = listFile;
}
class customCell : DataGridViewTextBoxCell
{
protected override object GetValue(int rowIndex)
{
string strValue = base.GetValue(rowIndex).ToString();
if (!this.Selected)
{
return System.IO.Path.GetFileName(strValue);
}
else
{
return strValue;
}
}
}
class customCol : DataGridViewTextBoxColumn
{
public customCol()
{
this.CellTemplate = new customCell();
}
}
}
|
|
|
|
|
Date :
2018-01-26 18:19:56 |
By :
SandKing |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|