datagridview

Refresh DataGridView after data inserted in DB by another dialog

南楼画角 提交于 2020-01-06 04:30:06
问题 On my Winforms app, I have a primary form with a DataGridView bound to a database Entity datasource. The grid is set up not to allow inserts. Instead I have a button on my form that kicks of a second dialog where the insert takes place (ie. with friendlier ui than is possible with the DataGridView). The insert is working fine.. query of the underlying table in db shows that the record has been inserted. However, I can't seem to get the DataGridView on the primary form to see the new data just

Winforms DataGridView custom edit control/cell

时间秒杀一切 提交于 2020-01-06 04:03:28
问题 I'm creating a custom editing control for my DataGridView in my winforms application, and I'd like to raise an event when the user hits the enter key, but before the datagridview scrolls to the next row. I don't really care if the event is raised by the cell, or the editing control as I can propagate the event as needed. So far I've tried to override both the OnKeyDown and OnKeyUp methods of the DataGridViewTextBoxCell class which I'm inheriting from and neither of these methods seems to be

How to highlight search text in DataGridView?

北战南征 提交于 2020-01-06 03:48:06
问题 I want to highlight the given search text in the DataGridView . I have tried cellFormatting event to find the bounds of the searchtext and draw FillRectangle , but i could not exactly get the bounds of the search text. In the added image, i have tried to highlight text "o" but it highlights other characters also. Could anyone share me how to draw perfect rectangle to highlight the searched text. Regards, Amal Raj. 回答1: You need to use the CellPainiting event. Try this code: string keyValue =

Display images in a DataGridView column using JSON objects as DataSource

≡放荡痞女 提交于 2020-01-06 03:16:18
问题 How would I go about formatting a DataGridView column to show an image from a URL instead of the URL itself as string. Example of what the DataGridView currently looks like: I currently have the following code: DataGridView1.DataSource = Tesco.uk.ghs.products.results Here I am binding the JSON I have to datagridview1 . This works (even though as you can see from the screenshot it seems to miss out the Description Column for some reason). I have also tried using the class

How can I show the subjects as column headers, as well as the student name and total mark

谁说胖子不能爱 提交于 2020-01-06 02:31:25
问题 I have 4 tables in my Microsoft SQL Server Db: Subject, Student, Exam and ExamResults. Subject table columns: SubjectID,SubjectName Student table columns: StudentID,Fname,Lname Exam table columns: ExamID,ExamDate,ExamPeriod,Class ExamResults column: ExamResultID,ExamID,StudentID,SubjectID,Result I am using the following query to get the results on a winforms datagridview (which I'm hosting on a wpf application): "SELECT SubjectName, Subject.SubjectID,Result, Fname, Lname FROM Subject " +"LEFT

retrieving number value from datagridview C#

僤鯓⒐⒋嵵緔 提交于 2020-01-06 02:29:11
问题 I am trying to retrieve a numerical value from datagridview. The data type for both the value in the table, and the variable (weeklyTotal), are integer. Also I am trying to cast it into integer. I looked through the whole website for similar problems, and yet none of the solutions were helpful. The error message that I am getting is “when casting form a number, the value must be less than infinity”. I went back to my table more than one time to make sure that I don’t have invalid value. it's

Winforms - Position new form directly under Datagridview selected row of parent

ⅰ亾dé卋堺 提交于 2020-01-06 01:54:10
问题 I have a form with a DataGridView on it. I select a row (always a single row) of data. After I click a button I would like to open a new form and always position it directly under the selected row. How should I do this? In my button click I do something like this: private void myBtn_Click(object sender, EventArgs e) { if (myDGV.SelectedCells.Count > 0) { int i = myDGV.SelectedCells[0].RowIndex; DataGridViewRow r = myDGV.Rows[i]; // READ SOME DATA FROM THE ROW newForm form = new newForm(); /

DataGridView doesn't update Enum in BindingList

假装没事ソ 提交于 2020-01-06 01:37:27
问题 The DataSource of my DataGridView is a BindingList<Filter> which contains an enum. The gridview contains only two columns: a regular textbox column for a string, and a combobox (drop down) column for the enum. If I bind the combobox column to the enum variable of my object I get an error. Here is the code for my objects: public class FilterProfile { public FilterProfile() { filters = new BindingList<Filter>(); // the list that gets bound to gridview } public string name { get; set; } public

Refresh datagridview records from another form

纵饮孤独 提交于 2020-01-05 11:52:45
问题 I have dataGridView1 in form1 but for inserting in it I'm using form2 which have save button (that provides insert into datagridview1) to which I'm trying to set - refresh or select * from so I dont need any refresh button in form1 whenever I want to show up just all the recors. Is there any way to achieve that? Thanks much for your time. 回答1: You can use delegate.. For example : Form1 : private void btnForm1_Click(object sender, System.EventArgs e) { // Create an instance of form 2 Form2

How do I add checked item(s) in my checkedlistbox to a DataGridView?

末鹿安然 提交于 2020-01-05 09:32:36
问题 I have a dropdownlist that selects category list from Database and display the product name onto the checkedlistbox. But how do I grabs the checked items from the checkedlistbox to the DataGridView? This is how my design looks like: Also, how do I make every medication that has been added to the Gridview has a default value of 1 Quantity? 回答1: Add this code to your Add button click event: private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < checkedListBox1.Items.Count;