我已尝试在C#中显示来自特定列ListView
的数据,但它是成功的。但我无法在GridControl
DevExpress中将其显示在特定列中。
这是ListView
中的代码:
OracleCommand cmd = new OracleCommand();
OracleDataReader dr;
cmd.CommandText = @"SELECT * FROM PERMOHONANDETAIL WHERE PERMOHONANFK = '" + buka.txtID.Text + "'";
cmd.Connection = koneksi_manual.con;
dr = cmd.ExecuteReader();
while (dr.Read())
{
ListViewItem list = new ListViewItem(dr["PEKERJAAN"].ToString());
list.SubItems.Add(dr["KODEPEKERJAAN"].ToString());
list.SubItems.Add(dr["PEKERJAAN"].ToString());
list.SubItems.Add(dr["JOBFORM"].ToString());
list.SubItems.Add(dr["QTYORDER"].ToString());
list.SubItems.Add(dr["TARGETPERHARI"].ToString());
list.SubItems.Add(Convert.ToDateTime(dr["TANGGALSTART"]).ToString("dd/MM/yyyy"));
list.SubItems.Add(Convert.ToDateTime(dr["TANGGALEND"]).ToString("dd/MM/yyyy"));
list.SubItems.Add(dr["DURASIHARI"].ToString());
list.SubItems.Add(dr["NOTES"].ToString());
buka.listView1.Items.Add(list);
}
dr.Close();
buka.Focus();
buka.ShowDialog();
如何在DevExpress中将其添加到特定列GridControl
?
我怎么解决这个问题?
答案 0 :(得分:1)
您可以为行创建一个类,并使用List<YourClass>
DataSource
作为GridControl
。
例如,您可以创建此类:
public class GridControlItem
{
public string KODEPEKERJAAN { get; set; }
public string PEKERJAAN { get; set; }
public string JOBFORM { get; set; }
public string QTYORDER { get; set; }
public string TARGETPERHARI { get; set; }
public string TANGGALSTART { get; set; }
public string TANGGALEND { get; set; }
public string DURASIHARI { get; set; }
public string NOTES { get; set; }
}
并在GridControl
中使用它,如下所示:
OracleCommand cmd = new OracleCommand();
OracleDataReader dr;
cmd.CommandText = @"SELECT * FROM PERMOHONANDETAIL WHERE PERMOHONANFK = '" + buka.txtID.Text + "'";
cmd.Connection = koneksi_manual.con;
dr = cmd.ExecuteReader();
var list = new List<GridControlItem>();
while (dr.Read())
{
var item = new GridControlItem();
item.KODEPEKERJAAN = dr["KODEPEKERJAAN"].ToString();
item.PEKERJAAN = dr["PEKERJAAN"].ToString();
item.JOBFORM = dr["JOBFORM"].ToString();
item.QTYORDER = dr["QTYORDER"].ToString();
item.TARGETPERHARI = dr["TARGETPERHARI"].ToString();
item.TANGGALSTART = Convert.ToDateTime(dr["TANGGALSTART"]).ToString("dd/MM/yyyy");
item.TANGGALEND = Convert.ToDateTime(dr["TANGGALEND"]).ToString("dd/MM/yyyy");
item.DURASIHARI = dr["DURASIHARI"].ToString();
item.NOTES = dr["NOTES"].ToString();
list.Add(item)
}
dr.Close();
gridControl1.DataSource = list;