本文整理汇总了C#中System.Windows.Forms.DataGridView类的典型用法代码示例。如果您正苦于以下问题:C# DataGridView类的具体用法?C# DataGridView怎么用?C# DataGridView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataGridView类属于System.Windows.Forms命名空间,在下文中一共展示了DataGridView类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);//事件的重载
}
开发者ID:mahuidong,项目名称:c-1200-II,代码行数:31,代码来源:PrintClass.cs
示例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();
};
}
开发者ID:ConradoClark,项目名称:ProjetoAdv,代码行数:34,代码来源:BeneficioCadastro.cs
示例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);
}
开发者ID:MisuBeImp,项目名称:DhakaUniversityCyberCenterUserApps,代码行数:27,代码来源:CardUsageController.cs
示例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();
}
开发者ID:waffleShirt,项目名称:DD-Tune-Track,代码行数:12,代码来源:TuneList.cs
示例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);
}
开发者ID:uc12706501,项目名称:ExpertCore,代码行数:26,代码来源:LevelDisplayForm.cs
示例6: OptionsManager
public OptionsManager(IBClient ibClient, DataGridView callGrid, DataGridView putGrid, DataGridView optionPositionsGrid)
{
this.ibClient = ibClient;
this.callGrid = callGrid;
this.putGrid = putGrid;
this.positionsGrid = optionPositionsGrid;
}
开发者ID:conradakunga,项目名称:QuantTrading,代码行数:7,代码来源:OptionsManager.cs
示例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);
}
}
开发者ID:juanmjacobs,项目名称:gestion2c2013,代码行数:30,代码来源:Listado.cs
示例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;
}
开发者ID:jwickberg,项目名称:libpalaso,代码行数:31,代码来源:GridSettings.cs
示例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);
}
}
开发者ID:piotrosz,项目名称:DebugVisualizersCollection,代码行数:31,代码来源:FormCollectionVisualizer.cs
示例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();
}
}
开发者ID:agallen,项目名称:AppJsonFfcv,代码行数:27,代码来源:Form1.cs
示例11: NewAssDlg
public NewAssDlg(MainForm f, DataGridView dv)
{
InitializeComponent();
mf = f;
mf.recvEvent += new MainForm.RecvEventHandler(this.RecvDataEvent);
dataGridView1 = dv;
}
开发者ID:chutinhha,项目名称:asset-management-system,代码行数:7,代码来源:NewAssDlg.cs
示例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);
}
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:7,代码来源:clsGiaoDienMau.cs
示例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);
}
}
开发者ID:przemyslaw-szymanski,项目名称:dungeonworld,代码行数:35,代码来源:CItemGrid.cs
示例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);
}
开发者ID:tatar1nro,项目名称:KKM_Trash,代码行数:33,代码来源:ExportXLS.cs
示例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();
}
};
}
开发者ID:SiGhTfOrbACQ,项目名称:O2.Platform.Scripts,代码行数:30,代码来源:ascx_SimpleFileSearch.cs
示例16: medie
private double medie(DataGridView dgv)
{
int sum = 0;
for (int i = 0; i < dgv.Rows.Count; i++)
sum += Convert.ToInt32(dgv.Rows[i].Cells[1].Value);
return Math.Round((double)sum / (dgv.RowCount - 1),2);
}
开发者ID:am1guma,项目名称:PSSC,代码行数:7,代码来源:UPT.cs
示例17: FormulaireModif
public FormulaireModif(int idServ,int pIdEtat,DataGridView pTableau)
{
idService = idServ;
idEtat = pIdEtat;
tableau = pTableau;
InitializeComponent();
}
开发者ID:projetgsb2013,项目名称:m2lPPE,代码行数:7,代码来源:FormulaireModif.cs
示例18: Initialize
public static void Initialize(DataGridView dataGridView)
{
if (dataGridView == null)
throw new ArgumentNullException("dataGridView");
m_DataGridView = dataGridView;
}
开发者ID:Steeslice,项目名称:StealthNet-Alt,代码行数:7,代码来源:SearchResultInformationDialog.cs
示例19: hienthi
public void hienthi(DataGridView data)
{
doc.Load(tentep);
data.Rows.Clear();
//Tạo nút gốc
XmlElement goc = doc.DocumentElement;
//Tạo đối tương ds chứa danh sách các nút
XmlNodeList ds = doc.SelectNodes("/congty/nhanvien");
int sd = 0;
data.ColumnCount = 5;
data.Rows.Add();//Hàm tự động add thêm dòng dữ liệu
//Dùng vòng foreach để duyệt và chèn dữ liệu
foreach (XmlNode node in ds) {
//Chọn các phần tử và gán biến cho chúng
XmlNode manv = node.SelectSingleNode("manv");
XmlNode hoten = node.SelectSingleNode("hoten");
XmlNode ngaysinh = node.SelectSingleNode("ngaysinh");
XmlNode gioitinh = node.SelectSingleNode("gioitinh");
XmlNode hsluong = node.SelectSingleNode("hsluong");
//ADD nó vào các cột và hàng tương ứng
data.Rows[sd].Cells[0].Value = manv.InnerText.ToString();
data.Rows[sd].Cells[1].Value = hoten.InnerText.ToString();
data.Rows[sd].Cells[2].Value = ngaysinh.InnerText.ToString();
data.Rows[sd].Cells[3].Value = gioitinh.InnerText.ToString();
data.Rows[sd].Cells[4].Value = hsluong.InnerText.ToString();
data.Rows.Add();
sd++;
}
}
开发者ID:giokats,项目名称:Projects-1,代码行数:29,代码来源:Class_XL.cs
示例20: ResultTable
public ResultTable(DataGridView dataView, string[] names) // constructor. Uses array of names for column/row header labels
{
m_dataView = dataView;
m_results = new Result[m_numberOfSequences, m_numberOfSequences];
for (int i = 0; i < m_numberOfSequences; ++i)
{
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
column.HeaderText = "seq" + (i+1);
column.MaxInputLength = 8;
column.Width = 50;
DataGridViewCell cell = new DataGridViewTextBoxCell();
column.CellTemplate = cell;
m_dataView.Columns.Add(column);
}
for (int j = 0; j < m_numberOfSequences; ++j)
{
DataGridViewRow row = new DataGridViewRow(); // how can I remove the dumb current cell pointer that makes the header cells so big/obfuscates the header text?
row.HeaderCell.Value = "seq"+(j+1);
row.Height = 20;
for (int i = 0; i < m_numberOfSequences; ++i)
{
DataGridViewCell cell = new DataGridViewTextBoxCell();
row.Cells.Add(cell);
}
dataView.RowHeadersWidthSizeMode=DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
m_dataView.Rows.Add(row);
}
dataView.CurrentCell = null;
}
开发者ID:YazanHalawa,项目名称:CS-312,代码行数:30,代码来源:ResultTable.cs
注:本文中的System.Windows.Forms.DataGridView类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论