本文整理汇总了C#中System.Windows.Forms.DataGridView.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridView.ToString方法的具体用法?C# DataGridView.ToString怎么用?C# DataGridView.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGridView
的用法示例。
在下文中一共展示了DataGridView.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: cargarDataGridViewConciliacionAutomatica
public void cargarDataGridViewConciliacionAutomatica(DataGridView dgv, IEnumerable<Object> lista, String p_modoEdicion, bool crea_encabezados)
{
try
{
Trace.TraceInformation(dgv.ToString());
Trace.TraceInformation(lista.ToString());
if (crea_encabezados)
{
//dgv.Rows.Clear();
dgv.Columns.Clear();
foreach (var item in lista)
{
Type t = item.GetType();
PropertyInfo[] pi = t.GetProperties();
foreach (PropertyInfo p in pi)
{
DataGridViewColumn columna = new DataGridViewColumn();
DataGridViewCell cell = new DataGridViewTextBoxCell();
columna.CellTemplate = cell;
columna.Name = p.Name;
columna.HeaderText = p.Name;
columna.ReadOnly = true;
columna.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
switch ( columna.Name )
{
case "NIVEL": columna.Visible = false; break;
case "IdArchivoTarjetaDetalle": columna.Visible = false; break;
}
dgv.Columns.Add(columna);
}
break;
}
DataGridViewCheckBoxColumn doWork = new DataGridViewCheckBoxColumn();
doWork.Name = "CONCILIAR";
doWork.HeaderText = "CONCILIAR";
doWork.FalseValue = "0";
doWork.TrueValue = "1";
dgv.Columns.Add(doWork);
} //crea_encabezados
var i=0;
foreach (object item in lista)
{
this.progressBar1.BringToFront();
dgv.Refresh();
//System.Threading.Thread.Sleep(10);
Application.DoEvents();
this.progressBar1.Increment(i++);
var row = dgv.Rows.Add();
dgv.Rows[row].HeaderCell.Value = i.ToString();
Type t = item.GetType();
PropertyInfo[] pi = t.GetProperties();
foreach (PropertyInfo p in pi)
{
Console.WriteLine(p.Name + " " + p.GetValue(item, null));
dgv.Rows[row].Cells[p.Name].Value = p.GetValue(item, null);
}
if (p_modoEdicion == "SI")
{
dgv.Rows[row].Cells["CONCILIAR"].Value = true;
}
switch (dgv.Rows[row].Cells["NIVEL"].Value.ToString())
{
case "-1": dgv.Rows[row].Cells["CONCILIAR"].Value = false;
dgv.Rows[row].ReadOnly = true;
dgv.Rows[row].DefaultCellStyle.BackColor = Color.White;
dgv.Rows[row].DefaultCellStyle.ForeColor = Color.Black;
break;
case "1": dgv.Rows[row].DefaultCellStyle.BackColor = Color.DarkGreen;
dgv.Rows[row].DefaultCellStyle.ForeColor = Color.White;
dgv.Rows[row].Cells["CONCILIAR"].Value = true;
break;
case "2": dgv.Rows[row].DefaultCellStyle.BackColor = Color.LightBlue; break;
case "3": dgv.Rows[row].DefaultCellStyle.BackColor = Color.Orange; break;
case "4": dgv.Rows[row].DefaultCellStyle.BackColor = Color.OrangeRed; break;
default:
dgv.Rows[row].Cells["CONCILIAR"].Value = false;
dgv.Rows[row].ReadOnly = true;
dgv.Rows[row].DefaultCellStyle.BackColor = Color.White;
dgv.Rows[row].DefaultCellStyle.ForeColor = Color.Black;
break;
}
dgv.Rows[row].Cells["FECHA_PAGO"].Value = dgv.Rows[row].Cells["FECHA_PAGO"].Value .ToString().Remove(10);
}
dgv.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
//.........这里部分代码省略.........
示例2: ExportToExcel
/// <summary>
/// Exports a grid to Excel
/// </summary>
/// <param name="dGv">The DataGridView to export to Excel</param>
/// <param name="saveName">The name that the excel file will be saved as</param>
/// <returns>If the grid was successfully exported and file saved</returns>
public static bool ExportToExcel(DataGridView dGv, string saveName)
{
dgvToExport = dGv;
string strExtension = ".xls";
string fullname = "";
int rowIndex = 1;
int row = 0;
string st1 = "";
if (dgvToExport != null)
{
try
{
saveName = checkFileExists(saveName, strExtension, pathExports);
fullname = pathExports + saveName + strExtension;
StreamWriter sw = new StreamWriter(fullname, false);
sw.AutoFlush = true;
for (int col = 0; col < dgvToExport.Columns.Count; col++)
{
if (dgvToExport.Columns[col].Visible == true)
{
if (col == 0)
{
sw.Write(dgvToExport.Columns[col].HeaderText.ToLower() + "\t");
}
else
{
sw.Write(dgvToExport.Columns[col].HeaderText + "\t");
}
}
}
for (row = 0; row < dgvToExport.Rows.Count; row++)
{
if (rowIndex <= dgvToExport.Rows.Count)
rowIndex++;
st1 = "\n";
for (int col = 0; col < dgvToExport.Columns.Count; col++)
{
if (dgvToExport.Columns[col].Visible == true)
{
if (dgvToExport.Rows[row].Cells[col].Value == null)
{
st1 += "NULL";
}
else
{
st1 += dgvToExport.Rows[row].Cells[col].Value.ToString();
}
st1 = st1 + "\t";
}
}
sw.Write(st1);
}
sw.Close();
FileInfo fil = new FileInfo(fullname);
if (fil.Exists == true)
{
if (MessageBox.Show("Grid has been exported to file" + Environment.NewLine + fil.FullName + Environment.NewLine + "Do you want to open file now?", "Export To Excel", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
CCFBGlobal.openDocumentOutsideCCFB(fil.FullName);
}
return true;
}
}
catch (Exception ex)
{
FileInfo file = new FileInfo(pathExports + saveName + strExtension);
appendErrorToErrorReport(dgvToExport.ToString(), ex.GetBaseException().ToString());
MessageBox.Show("ERROR: Could not export the grid.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
}
return false;
}