datagridview

DataGridView Changing DataSource Dynamically

我们两清 提交于 2020-01-03 16:04:21
问题 Basically when I create this DataGridView I have this code to fill it up public void fillDataGrid(IQueryable<PatientInfo> patients) { dgvMyPatients.DataSource = patients; dgvMyPatients.Columns["Pat_Last_Name"].DisplayIndex = 0; dgvMyPatients.Columns["Pat_First_Name"].DisplayIndex = 1; dgvMyPatients.Columns["Pat_Middle_Name"].DisplayIndex = 2; dgvMyPatients.Columns["Pat_First_Name"].HeaderText = "First Name"; dgvMyPatients.Columns["Pat_Last_Name"].HeaderText = "Last Name"; dgvMyPatients

How to populate a dataGridView with an array of user generated integers

匆匆过客 提交于 2020-01-03 12:57:59
问题 With this: dataGridView.DataSource = theData.Select((x, index) => new { CreatureRoll = x, CreatureLabel = index}).OrderByDescending(x => x.CreatureRoll).ToList(); It produces the data correctly, But it produces all the rows in the array with extra data that will not be useful, empty data. img http://s21.postimg.org/t3f34aa43/list_Result.jpg?noCache=1379353500 Would like to remove unnecessary rows of data 回答1: You can use LINQ to generate the datasource from a array. int[] theData = new int[]

DataGridView row is still dirty after committing changes

▼魔方 西西 提交于 2020-01-03 11:49:33
问题 DataGridView.IsCurrentRowDirty remains true after I commit changes to the database. I want to set it to false so it doesn't trigger RowValidating when it loses focus. I have a DataGridView bound to a BindingList<T> . I handle the CellEndEdit event and save changes to the database. After saving those changes I would like DataGridView.IsCurrentRowDirty to be set to true , since all cells in the row are up-to-date; however, it's set to false . This causes problems for me because when the row

How do I get the selected row data from a data grid view using SelectedRows?

爷,独闯天下 提交于 2020-01-03 11:00:00
问题 I have a table that I am displaying in a data grid view control. The user selects a single row from the control and presses a button. I need to retrieve the cells from that row and store them as strings. Exactly how do I get the data using the SelectedRow method? I've been working on this for several hours and I'm at the end of my rope. Here's an example of something I've tried: DataGridViewCellCollection selRowData = dataGridView1.SelectedRows[0].Cells; If I try to access selRowData[x], the

CellValueChanged vs CellValidating Events for DataGridView

别说谁变了你拦得住时间么 提交于 2020-01-03 07:32:11
问题 What's the best place to implement validation logic code and conditional formatting code for a DataGridView? In a lot of books and articles that I've read on this control, it seems to suggest that the appropriate event to handle for this is the CellValidating one. Well, the name more than implies this as well. However, this event triggers a bit too often for my tastes and I'm not sure it is required. For example, this event triggers everytimes the users switches to another row. On the other

Update a datagridview having combobox with bindingsource

廉价感情. 提交于 2020-01-03 05:55:42
问题 I am using Vb.Net to load data from sql server database. I have the car datatable as follows: I load car details and distinct model values as follows: sql = " select * from car" daCar = New SqlDataAdapter(sql, sqlConn) daCar.Fill(dsDataset, "car") sql = " select distinct model from car" daCar = New SqlDataAdapter(sql, sqlConn) daCar.Fill(dsDataset, "model") Now when I load the form I have two bindingsources and have one combobox to display the distinct values of the model so user car modify

Creating chart from datagridview C#

痞子三分冷 提交于 2020-01-03 05:50:23
问题 Good day, i have a little problem. I'm trying to make chart from dataGridView so i wrote short code. private void create_graphs_Click(object sender, EventArgs e) { Chart chart1 = new Chart(); chart1.Series[0] = new Series(); chart1.Series[0].XValueMember = dataGridView1.Columns[0].DataPropertyName; chart1.Series[0].YValueMembers = dataGridView1.Columns[1].DataPropertyName; chart1.DataSource = dataGridView1.DataSource; chart1.Series[0].ChartType = SeriesChartType.Line; chart1.SaveImage("chart

displaying data from multiple tables in datagridview

六月ゝ 毕业季﹏ 提交于 2020-01-03 05:38:05
问题 I have a list of tables in one column n checkboxes in another column. I want to view data of the tables which I select by clicking on the checkboxes My code is for (int i = 0; i < dataGridView2.Rows.Count; i++ ) { if (dataGridView2.Rows[i].Cells[1].Value != null) { if ((Boolean)dataGridView2.Rows[i].Cells[1].Value == true) { try { string myConnection="datasource=localhost;database=dmrc;port=3306;username=root;password=root"; MySqlConnection myConn = new MySqlConnection(myConnection); string

Trouble using DataGridViewComboboxColumn for input

吃可爱长大的小学妹 提交于 2020-01-03 05:06:33
问题 I have a datagridview which I'm using for data entry. I've done this before with all text columns, and it worked great. But now I want one of the columns to be a databound combobox so the user can select options. When I do this, the resulting gridview's datasource ends up with empty rows (but the right quantity). What am I missing? Here is code: DataGridViewComboBoxColumn cboCategory = new DataGridViewComboBoxColumn(); { cboCategory.HeaderText = "Category"; cboCategory.DataSource =

CancelEdit does not keep focus on edited cell in DataGridView c#

狂风中的少年 提交于 2020-01-03 04:55:29
问题 When I enter some value in a cell in DataGridView and click on another cell the cellvalidating event handler code is executed. Even if validation fills, the cell on which I click gets highlighted. My requirement is that the cell should remain selected and cursor should blink in the cell for editing after removing the invalid value. Am using the below code if the validation fails: DataGridView1.CancelEdit(); I have tried adding DataGridView1.CurrentCell.Selected = true; DataGridView1.BeginEdit