datagridview

Passing Value from One Form to Another (C#)

我的梦境 提交于 2019-12-31 07:32:04
问题 I have a search form in my program. When the user double-clicks a cell (of the dgv) on the search form, I want the program to close that form and jump to the item on the main form. I'm doing this by identifying each item with a unique id. I'm trying to pass the value of the rows id to the other form. The problem is that, it says that I'm passing the value zero each time. But when I insert some message boxes on the search form, it says that the integer 'id' has successfully been assigned to

How to bind DataGridView's multiple columns to a custom class's fields?

亡梦爱人 提交于 2019-12-31 07:29:13
问题 Suppose I have a simple class, and list of its instances: public class Class1 { public int a; public int b; } List<Class1> l = new List<Class1>(); l.AddRange(new[] { new Class1 { a = 1, b = 2 }, new Class1 { a = 3, b = 4 } }); How do I bind a DataGridView with columns for a and b to it? I've found answers, but not any that work. This should be simple, but I can't figure it out. 回答1: assuming that you have columns colA and colB , set their DataPropertyName property and set grid DataSource colA

Scrolling DataGridView per pixel

微笑、不失礼 提交于 2019-12-31 05:46:05
问题 I am making a .NET 4 WinForms application which reads data from a database and displays rows in a DGV. However the number of rows is larger than maximum number of rows that can fit on screen at once. To display all data, I need to scroll the DGV automatically until the last row and update the data source after that in order to refresh the DGV. I found it's easy to do that by simply incrementing FirstDisplayedScrollingRowIndex by one. However the scrolling is too sharp. I would like it to

Alternative to DataGridView DataBindingComplete Event

落花浮王杯 提交于 2019-12-31 04:57:14
问题 As stated here the DataBindingComplete event for a DataGridView is fired whenever the contents of the data source change, or a property such as DataSource changes. This results in the method being called multiple times. I am currently using the DataBindingComplete event to do some visual formatting to my form. For example, I make the text in the first column (column 0) appear as Row Headers and then hide that column (see code below). private void grdComponents_DataBindingComplete(object

How to count specific values in a column of datagridview column

北慕城南 提交于 2019-12-31 04:37:10
问题 In a DataGridView I need to count how many duplicate values a column has. This is my Datagridview: For example, I'd like to count how many "X" I have in my "RisFin" column, and put the result in a textbox. 回答1: You can count what you need this way: var count= this.dataGridView1.Rows.Cast<DataGridViewRow>() .Count(row => row.Cells["RisFin"].Value == "X"); this.textBox1.Text = count.ToString(); Using linq queries you can simply do many things with your grid. and the key point is casting the

How to add datagridview rows to an xml file?

半世苍凉 提交于 2019-12-31 04:11:09
问题 I am a beginner in c#, I created one dataGridView1 in a Form to which I added some rows and columns ( without using DataSet and Datatable ). Now I need to send the data of dataGridView1 to an xml file. The xml file should update whenever I click on that button. I need to do this without using Datatable (or tables). I tried the below code ( not working ) OnButtonClick XmlTextWriter newXml = new XmlTextWriter("d:/newXML.xml", Encoding.UTF8); DataSet ds = new DataSet(dataGridView1.Rows.ToString(

How to force DataGridView current cell outline without pressing Tab

*爱你&永不变心* 提交于 2019-12-31 03:14:08
问题 Is there someway to make it so the current cell of the DataGridView always has the dashed-line border around it that you get when you press the Tab button? I've noticed that if you've pressed the Tab button once after that the current cell always has the border around it, but I'd like to have that border there from the start, without having to press the Tab button. Currently I'm programmatically sending the Tab key, as below: SendKeys.Send("{TAB}"); But this is kludgy and I'd rather have a

DataGridView CellPainting Not Fully Working on Scroll

心已入冬 提交于 2019-12-31 03:02:44
问题 First post, but long time browser :) So here's my problem: Basically I have a datagridview that I am using to interact with the user. In all of the rows, there is an "info" button that will give the illusion that it adds another row below it with all of the cells merged (one long cell across entire row) and draws the text and images describing the row above it onto the "info cell". This works great except when the datagridview is scrolled vertically, then it appears that the painting isn't

how to change text in datagridview text on condition .

[亡魂溺海] 提交于 2019-12-31 03:01:17
问题 I am using a datagridview and I want to display do conditional formatting means when I get for a cell M then I want to display Married .I try this but not sucess. Here is my code: private void masterDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { try { for (int i = 0; i <= masterDataGridView.Rows.Count - 1; i++) { String Value = masterDataGridView.Rows[i].Cells[17].Value.ToString(); if (Value == "M") { e.Value = "Male"; } } } catch (Exception ex) { } } 回答1:

Bit datatype to enum type mapping from database to dataset in SQL Server 2008

社会主义新天地 提交于 2019-12-31 00:44:39
问题 I have a table which has a column Xyz and it has bit datatype in SQL Server 2008. I'm getting the values from the table through data adapter and I'm storing it in a DataSet and a DataGridView will show the contents from the DataSet In the gridview, for column Xyz , a check_box with/without tick is displayed but I want to display it as a buy/sell as a text instead of checkbox. 回答1: You can handle it in 1 of 2 ways. 1) Instead of returning the data as a bit, do the casting in your query to have