本文整理汇总了C#中System.Windows.Forms.DataGridView类的典型用法代码示例。如果您正苦于以下问题:C# DataGridView类的具体用法?C# DataGridView怎么用?C# DataGridView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataGridView类属于System.Windows.Forms命名空间,在下文中一共展示了DataGridView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrintClass
/// <summary>
/// 打印信息的初始化
/// </summary>
/// <param datagrid="DataGridView">打印数据</param>
/// <param PageS="int">纸张大小</param>
/// <param lendscape="bool">是否横向打印</param>
public PrintClass(DataGridView datagrid, int PageS, bool lendscape)
{
this.datagrid = datagrid;//获取打印数据
this.PageSheet = PageS;//纸张大小
printdocument = new PrintDocument();//实例化PrintDocument类
pagesetupdialog = new PageSetupDialog();//实例化PageSetupDialog类
pagesetupdialog.Document = printdocument;//获取当前页的设置
printpreviewdialog = new PrintPreviewDialog();//实例化PrintPreviewDialog类
printpreviewdialog.Document = printdocument;//获取预览文档的信息
printpreviewdialog.FormBorderStyle = FormBorderStyle.Fixed3D;//设置窗体的边框样式
//横向打印的设置
if (PageSheet >= 0)
{
if (lendscape == true)
{
printdocument.DefaultPageSettings.Landscape = lendscape;//横向打印
}
else
{
printdocument.DefaultPageSettings.Landscape = lendscape;//纵向打印
}
}
pagesetupdialog.Document = printdocument;
printdocument.PrintPage += new PrintPageEventHandler(this.printdocument_printpage);//事件的重载
}
示例2: BeneficioCadastro
public BeneficioCadastro(
ButtonBase botaoSalvar,
ButtonBase botaoCancelar,
Form tela,
DataGridView beneficioGridView
)
{
this.Botao_Salvar = botaoSalvar;
this.Botao_Cancelar = botaoCancelar;
this.Tela = tela;
Beneficios = TiposBeneficio.ObterListaAssociada();
beneficioGridView.AutoGenerateColumns = false;
beneficioGridView.DataSource = Beneficios;
Botao_Salvar.Click += new EventHandler(Botao_Salvar_Click);
Botao_Cancelar.Click += new EventHandler(Botao_Cancelar_Click);
Beneficios.AddingNew += (sender, args) =>
{
if (beneficioGridView.Rows.Count == Beneficios.Count)
{
Beneficios.RemoveAt(Beneficios.Count - 1);
return;
}
};
AoCancelar += () =>
{
beneficioGridView.DataSource = Beneficios;
};
AoSalvar += () =>
{
TiposBeneficio.DispararAtualizacao();
};
}
示例3: ExpotToExcel
public void ExpotToExcel(DataGridView dataGridView1,string SaveFilePath)
{
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int i = 0;
int j = 0;
for (i = 0; i <= dataGridView1.RowCount - 1; i++)
{
for (j = 0; j <= dataGridView1.ColumnCount - 1; j++)
{
DataGridViewCell cell = dataGridView1[j, i];
xlWorkSheet.Cells[i + 1, j + 1] = cell.Value;
}
}
xlWorkBook.SaveAs(SaveFilePath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
MessageBox.Show("Your file is saved" + SaveFilePath);
}
示例4: TuneList
/// <summary>
/// TuneList Constructor.
/// </summary>
/// <param name="appForm">Main application form</param>
/// <param name="dgv">DataGridView from main application form</param>
public TuneList(DDTuneTrackForm appForm, DataGridView dgv)
{
mAppForm = appForm;
mTuneListDGV = dgv;
InitializeDataGridView();
}
示例5: Init
private void Init()
{
DataGridView dgv = new DataGridView()
{
Width = 700,
ReadOnly = true,
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells,
};
dgv.DataSource = _level.GetTotalWeightVect().Transpose().ToDataTable();
//设置显示格式
dgv.CellFormatting += (sender, e) =>
{
//不处理新建行
if (e.RowIndex != dgv.NewRowIndex)
{
double d = double.Parse(e.Value.ToString());
e.Value = d.ToString("N3");
}
};
totalSortPanel.Controls.Add(dgv);
ciLabel.Text = string.Format("CI={0:f4}", _level.LevelCI);
riLabel.Text = string.Format("RI={0:f4}", _level.LevelRI);
crLabel.Text = string.Format("CR={0:f4}", _level.LevelCR);
}
示例6: OptionsManager
public OptionsManager(IBClient ibClient, DataGridView callGrid, DataGridView putGrid, DataGridView optionPositionsGrid)
{
this.ibClient = ibClient;
this.callGrid = callGrid;
this.putGrid = putGrid;
this.positionsGrid = optionPositionsGrid;
}
示例7: listarMicros
public static void listarMicros(DataGridView dgMicros, String patente, String patenteEstimada,
String modelo, String modeloEstimado, DateTimePicker dtpFechaAlta, String marca, String tipoServicio,
decimal numero, bool mostrarDeshabilitados, bool mostrarHabilitados)
{
try
{
using (SqlConnection conn = new SqlConnection(main.connString))
using (SqlCommand cmd = new SqlCommand("BONDIOLA.listarMicros", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
SQL_Library.agregarParametro(cmd, "@patente", patente);
SQL_Library.agregarParametro(cmd, "@patenteEstimada", patenteEstimada);
SQL_Library.agregarParametro(cmd, "@modelo", modelo);
SQL_Library.agregarParametro(cmd, "@modeloEstimado", modeloEstimado);
SQL_Library.agregarParametroFecha(cmd, dtpFechaAlta, "@fecha_alta");
SQL_Library.agregarParametro(cmd, "@marca", marca);
SQL_Library.agregarParametro(cmd, "@tipoServicio", tipoServicio);
SQL_Library.agregarParametro(cmd, "@numero", numero);
SQL_Library.agregarParametro(cmd, "@mostrarDeshabilitados", mostrarDeshabilitados);
SQL_Library.agregarParametro(cmd, "@mostrarHabilitados", mostrarHabilitados);
SQL_Library.agregarParametro(cmd, "@fechaActual", Properties.Settings.Default.Fecha);
SQL_Library.llenarDataGrid(dgMicros, conn, cmd);
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
示例8: InitializeGrid
/// ------------------------------------------------------------------------------------
public void InitializeGrid(DataGridView grid)
{
foreach (var col in Columns)
{
if (!grid.Columns.Contains(col.Id))
continue;
grid.Columns[col.Id].Visible = col.Visible;
if (col.Width >= 0)
grid.Columns[col.Id].Width = col.Width;
if (col.DisplayIndex < 0)
grid.Columns[col.Id].DisplayIndex = 0;
else if (col.DisplayIndex >= grid.ColumnCount)
grid.Columns[col.Id].DisplayIndex = grid.ColumnCount - 1;
else
grid.Columns[col.Id].DisplayIndex = col.DisplayIndex;
}
if (!string.IsNullOrEmpty(SortedColumn) && grid.Columns.Contains(SortedColumn))
grid.Sort(grid.Columns[SortedColumn], SortOrder == SortOrder.Descending ? ListSortDirection.Descending : ListSortDirection.Ascending);
// If the column header height or the former dpi settings are different,
// then auto. calculate the height of the column headings.
if (ColumnHeaderHeight <= 0 || DPI != m_currDpi)
grid.AutoResizeColumnHeadersHeight();
else
grid.ColumnHeadersHeight = ColumnHeaderHeight;
}
示例9: Show
protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider provider)
{
using (Form form1 = new Form())
{
form1.Text = "FormCollection Visualizer";
form1.StartPosition = FormStartPosition.WindowsDefaultLocation;
form1.SizeGripStyle = SizeGripStyle.Auto;
form1.ShowInTaskbar = false;
form1.ShowIcon = false;
DataTable dt;
using (Stream stream = provider.GetData())
{
BinaryFormatter bformatter = new BinaryFormatter();
dt = (DataTable)bformatter.Deserialize(stream);
stream.Close();
}
DataGridView gridView = new DataGridView();
gridView.Dock = DockStyle.Fill;
form1.Controls.Add(gridView);
gridView.DataSource = dt;
windowService.ShowDialog(form1);
}
}
示例10: ExportarDataGridViewExcel
private void ExportarDataGridViewExcel(DataGridView grd)
{
SaveFileDialog fichero = new SaveFileDialog();
fichero.Filter = "Excel (*.xls)|*.xls";
if (fichero.ShowDialog() == DialogResult.OK)
{
Microsoft.Office.Interop.Excel.Application aplicacion;
Microsoft.Office.Interop.Excel.Workbook libros_trabajo;
Microsoft.Office.Interop.Excel.Worksheet hoja_trabajo;
aplicacion = new Microsoft.Office.Interop.Excel.Application();
libros_trabajo = aplicacion.Workbooks.Add();
hoja_trabajo =
(Microsoft.Office.Interop.Excel.Worksheet)libros_trabajo.Worksheets.get_Item(1);
//Recorremos el DataGridView rellenando la hoja de trabajo
for (int i = 0; i < grd.Rows.Count ; i++)
{
for (int j = 0; j < grd.Columns.Count; j++)
{
hoja_trabajo.Cells[i + 1, j + 1] = grd.Rows[i].Cells[j].Value.ToString();
}
}
libros_trabajo.SaveAs(fichero.FileName,
Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal);
libros_trabajo.Close(true);
aplicacion.Quit();
}
}
示例11: NewAssDlg
public NewAssDlg(MainForm f, DataGridView dv)
{
InitializeComponent();
mf = f;
mf.recvEvent += new MainForm.RecvEventHandler(this.RecvDataEvent);
dataGridView1 = dv;
}
示例12: getMa
public override string getMa(DataGridView grid)
{
DataGridViewRow row = grid.SelectedRows[0];
string MaMAU = row.Cells["MaMauVaChePhamMau"].Value.ToString();
return MaMAU;
//return base.getMaThuoc(grid);
}
示例13: CreateEmptyGrid
void CreateEmptyGrid()
{
m_Grid = new DataGridView();
m_Grid.ReadOnly = true;
m_Grid.Parent = this;
m_Grid.Dock = DockStyle.Fill;
m_Table = new DataTable();
m_Grid.DataSource = m_Table;
//Add base item attributes
Type ItemType = typeof(GameplayItem);
Type ItemAttrType = typeof(ItemAttributes);
System.Reflection.FieldInfo[] ItemFields = ItemType.GetFields();
System.Reflection.FieldInfo[] ItemAttrFields = ItemAttrType.GetFields();
List<string> FieldNames = new List<string>();
foreach (System.Reflection.FieldInfo Info in ItemFields)
{
FieldNames.Add(Info.Name);
DataGridViewColumn Col = new DataGridViewColumn(CreateCellTemplate(Info));
Col.Name = Info.Name;
//m_Grid.Columns.Add(Col);
m_Table.Columns.Add(Info.Name, Info.FieldType);
}
foreach (System.Reflection.FieldInfo Info in ItemAttrFields)
{
FieldNames.Add(Info.Name);
DataGridViewColumn Col = new DataGridViewColumn(CreateCellTemplate(Info));
Col.Name = Info.Name;
//m_Grid.Columns.Add(Col);
m_Table.Columns.Add(Info.Name, Info.FieldType);
}
}
示例14: ExportToExcel
public void ExportToExcel(DataGridView grid,string r_id,string time)
{
ApplicationClass Excel = new ApplicationClass();
XlReferenceStyle RefStyle = Excel.ReferenceStyle;
Excel.Visible = true;
Workbook wb = null;
String TemplatePath = System.Windows.Forms.Application.StartupPath + @"\Отчет"+r_id+".xlt";
try
{
wb = Excel.Workbooks.Add(TemplatePath); // !!!
}
catch (System.Exception ex)
{
throw new Exception("Не удалось загрузить шаблон для экспорта " + TemplatePath + "\n" + ex.Message);
}
Worksheet ws = wb.Worksheets.get_Item(1) as Worksheet;
ws.Cells[20, 3] = time;
for (int j = 0; j < grid.Columns.Count; ++j)
{
//(ws.Cells[1+20, j + 1+2] as Range).Value2 = grid.Columns[j].HeaderText;
for (int i = 0; i < grid.Rows.Count; ++i)
{
object Val = grid.Rows[i].Cells[j].Value;
if (Val != null)
(ws.Cells[i + 2+20, j + 1+2] as Range).Value2 = Val.ToString();
}
}
// ws.Columns.EntireColumn.AutoFit();
Excel.ReferenceStyle = RefStyle;
ReleaseExcel(Excel as Object);
}
示例15: buildGui
public void buildGui()
{
var topPanel = this.add_Panel();
Path = topPanel.insert_Above<TextBox>(20);
sourceCode = topPanel.add_SourceCodeEditor();
dataGridView = sourceCode.insert_Above<Panel>(100).add_DataGridView();
leftPanel = topPanel.insert_Left<Panel>(300);
Path.onEnter(loadFiles);
Path.onDrop(
(fileOrFolder)=>{
Path.set_Text(fileOrFolder);
loadFiles(fileOrFolder);
});
dataGridView.SelectionChanged+=
(sender,e) => {
if (dataGridView.SelectedRows.size() == 1)
{
var selectedRow = dataGridView.SelectedRows[0];
var filePath = selectedRow.Cells[0].Value.str();
var filename = selectedRow.Cells[1].Value.str();
var lineNumber = selectedRow.Cells[2].Value.str();
"opening up source code: {0}".info(filePath);
sourceCode.open(filePath.pathCombine(filename));
sourceCode.gotoLine(lineNumber.toInt() + 1);
dataGridView.focus();
}
};
}