datagridview

DataGridView - how to set the currency format for a single column ONLY

时间秒杀一切 提交于 2019-12-29 05:34:08
问题 I am trying to use the datagridview for a basket. I have got it to display the basket of the customer but I would like it to display the currency for the Price column, but i have a Quantity column as well, so if I put the default style as currency then it will change both columns to the currency format. What I want to be able to do is add the currency format to the Price Column but not to the quantity column. Here is the code that displays the basket (Form_load) using (var con = new

Do I need a BindingSource AND a BindingList for WinForms DataBinding?

百般思念 提交于 2019-12-29 04:21:24
问题 I want to display a list of people in a DataGridView in a Windows Forms app. I want my service layer to return a list of Person objects (e.g., IList<Person> ). I want changes in the list to be reflected in the DataGridView and vice versa. My understanding is that using the BindingSource facilitates working with DataGridView . My question is for the two-way databinding to work, do I need: //pseudo code BindingSource.DataSource = IBindingList<Person> or can I do: BindingSource.DataSource =

Populating a DataGridView with Text and ProgressBars

三世轮回 提交于 2019-12-29 03:22:45
问题 I am creating a multi-threaded application in which each thread will appear as a row in my DataGridView . I want a ProgressBar in each row indicating the corresponding thread progress. The question is, is this possible? And if so, how? 回答1: I added class DataGridViewProgressColumn.cs (source: MSDN) using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; using System.ComponentModel; namespace Sample { public class

replace true/false in datagridview columns

帅比萌擦擦* 提交于 2019-12-29 01:36:47
问题 I have a datagridview which I fill it as below : var q= repository.GetStudents();// dataGridView1.DataSource = null; dataGridView1.Columns.Clear(); dataGridView1.DataSource = q; dataGridView1.Columns.RemoveAt(1); //Remove IsActive //Cause I want to have my own implementation dataGridView1.Columns[0].DataPropertyName = "StudentID"; dataGridView1.Columns[0].HeaderText = "Studunet ID"; dataGridView1.Columns[1].DataPropertyName = "IsActive"; dataGridView1.Columns[1].HeaderText = "Status"; The

Is it possible to switch rows and columns in a datagridview?

痴心易碎 提交于 2019-12-28 23:08:07
问题 I have 10 records of data in a DataTable which has 3 fields "Foo", "Bar", and "Baz". If I connect wire this into a DataGridView I see 10 rows and 3 columns, and the column headers display the names of the fields. I'm wondering how easy it is to reverse the rows and columns so that with the same data I end up with 3 rows and 10 columns, with field names being displayed in the row headers. I can do some things manualy, like overriding an OnPaint method and drawing the field names directly into

How to Bind specific Columns of a datatable to a DataGridView?

为君一笑 提交于 2019-12-28 13:36:31
问题 My DataTable has three columns fetched from a database, while I need to bind only two columns of it to a DataGridView . Can you please help me with it? 回答1: Create the columns for the DataGridView yourself. Try something like this. DataGridView dataGridView1 = new DataGridView(); BindingSource bindingSource1 = new BindingSource(); dataGridView1.ColumnCount = 2; dataGridView1.Columns[0].Name = "Field1"; dataGridView1.Columns[0].DataPropertyName = "Field1"; dataGridView1.Columns[1].Name =

How do I allow edit only a particular column in datagridview in windows application?

人盡茶涼 提交于 2019-12-28 12:15:25
问题 I want to enable only two columns in the DataGridview to be able to edit. The others should not be allowed to edit. Further I am not directly linking to datasource; I will be doing some thing like this way DataTable dt = new DataTable(); dt.Columns.Add("Email"); dt.Columns.Add("email1"); for (int i = 0; i < 5; i++) { DataRow dr = dt.NewRow(); dr["Email"] = i.ToString(); dr["email1"] = i.ToString() + "sdf"; dt.Rows.Add(dr); } BindingSource bs = new BindingSource(); bs.DataSource = dt;

How to get DataGridView cell value in messagebox?

一个人想着一个人 提交于 2019-12-28 06:46:36
问题 How can I get DataGridView cell value to be written in the MessageBox in C#? 回答1: You can use the DataGridViewCell.Value Property to retrieve the value stored in a particular cell. So to retrieve the value of the 'first' selected Cell and display in a MessageBox, you can: MessageBox.Show(dataGridView1.SelectedCells[0].Value.ToString()); The above probably isn't exactly what you need to do. If you provide more details we can provide better help. 回答2: private void dataGridView1_CellClick(object

How to get DataGridView cell value in messagebox?

佐手、 提交于 2019-12-28 06:45:04
问题 How can I get DataGridView cell value to be written in the MessageBox in C#? 回答1: You can use the DataGridViewCell.Value Property to retrieve the value stored in a particular cell. So to retrieve the value of the 'first' selected Cell and display in a MessageBox, you can: MessageBox.Show(dataGridView1.SelectedCells[0].Value.ToString()); The above probably isn't exactly what you need to do. If you provide more details we can provide better help. 回答2: private void dataGridView1_CellClick(object

Looping each row in datagridview

懵懂的女人 提交于 2019-12-28 06:28:28
问题 How to loop each row that readed? in my code, the row won't bind to next row because of the same productID, so the datagridview won't move to new row, it still in the same row and overwrite the price (for some product, i have two price). How to loop it to show the same productID but it have different price. EX : 1 Hamburger have 2 price Hamburger : $1 and $2 when i get the data with looping it, the resould shoult be have 2 Row with same product but different price. How to do this? below is my