through C # I am creating a program that manages ambulances, I am trying to create a list with the events and active missions, this data must be taken from a mysql database, I have tried to see many "tutorials", but none explained what I needed, how do you think I can do something like this?
image here
in addition to displaying the data, if I click twice it should open the event or mission to me depending on where I click, (the icons are also buttons that should only be visible if there is a data)
just a tip! I'm not asking you to write the code for me!!!
EDIT:
I managed to get the data from mysql, that you know is it possible to place the data in specific columns?
Program
Code
It is difficult to guide you through such unspecific question, but I'll try some hints.
You said you have data from MySQL
Fill a DataTable (another way is to use BindingSource)
Assign DataTable as a DataSource of your DataGridView grid.
You can edit columns in the DataGridView using UI in VS, or you can do it programatically. First is easier, just note that if you at any stage provide Nothing as a data source, you'll loose column headers.
For event fired on DataGridViewRow, click on the grid in Designer, click on events in the Properties pane, find DatagridviewRow_DoubleClick and double click the line, to create associated method
FIll in the code into the even method. Use DataGridView.SelectedRows(0) to get selected row and it's index. If you want to "open it" create a modal dialog or what you want for displaying the content.
Related
I've got a program which is linked to a Microsoft Access database and what I want to do is to display data from a data column, for example, customerName from the table customerDetails into a label. The drag and drop feature from the data sources panel puts the data into text boxes by default however, I want mine in labels. I've looked around but I couldn't find anything directly referencing how to put data into different controls like labels so any help is appreciated!
One way is to change the default control type for your fields in Data Sources window. Since you are already using that method, simply go to Data Sources window, expand your table and select required field(s). Then select a different control type (Label in your case) from the list.
I'm pretty new to c# and Winforms and I'm wondering what is the best approach to the following screen design.
I have a window that contain a Datagrid wich would be read-only. Beneath the grid, I have the detail of the records in differents fields (textbox, combobox, checkbox).
What I want is that when the user click on an item in the datagrid, the data will be shown in the detail fields.
That part is pretty easy, but I want to be able to update the fields automatically, wich means, I would prefer to not have to press a Save button.
Let's say that I click an item in the datagrid, change some value in the detail fields and the I click on another item in the datagrid, then I also want to perform some validation and calculation before the record get updated.
What I was thinking at first was to get the button for "new", "edit", "save" action and lock and unlock the fields accordingly and keep a flag to know if i need to insert or update the data, but then I realized that I would prefer to not have thoses button and have the save performed automatically.
Is there any sample somewhere that does what I want?
Also, would you guys using the built-in databinding functunality or just use a dataset object in code?
Pretty common scenario.
On selected row change of grid you know which datarow you shoul bind to the other controls. when same event happens again you validate and save or cancel in case of errors.
You can make use of DataGridView.CellEndEdit Event to get the new value and DataGridView.CellBeginEdit event to get the old value and update your data if there is any change
I have this program in which I am trying to store a collection of values into a list and session
Example:
valueCollection = (List<Values>)Session["Value"];
I want to do the front end in a way which will show a table with each row showing a label and textbox. This would be too simple to do obviously but I want it to show 4 rows of the table by default and then the user can select "add another" this will then add another row onto the table with a label and textbox exactly similar to the 4 default. Everytime the user selects "add another" the table increments by 1.
How do you do something like that, or is there an easy way?
Here is a screenshot to explain it better:
http://img828.imageshack.us/img828/9986/idead.png
The basic idea is that you bind a control to your data and provide GUI controls to allow users to add/edit/delete records. Once the records are modified you re-bind the control to see the changes.
Take a look at the Databound controls in the .Net Framework. For a quick first pass you could use a ListView - a control which provides built-in functionality to automatically generate and mange the add/edit/delete GUI elements.
In 'real world' usage, storing big datasets isn't a great idea as more users = more sessions and each session uses server resources. You should really be getting/storing your data in a database or perhaps an XML file.
HTH
I am currently refactoring some of my old code that is pretty terrible. I will have a class that creates a Treeview, populates the node, etc and is displayed on a Winform.
Each node on the Treeview represents some data and when the user clicks on that then a datagridview is also displayed on the Winform. The datagridview will be generated within a new class also.
My idea on this is, when the Winform Loads, create and display the Treeview and use an event to monitor for node clicks. When the Winform handles such an event, then it creates the datagrid object and diplays that.
IS this the best way to architect this?
Thanks.
Yes, what you describe is a standard way to do things in WinForms.
You don't need to create the DataGridView every time though - just place it on the Form and in the event handler load the data from somewhere and change the contents of the DataGridView by assigning to DataGridView.DataSource.
In the form designer, define columns for DataGridView and set their DataPropertyName to the names of the corresponding properties of the data objects in the collection.
Note: the data assigned to the DataGridView.DataSource can be a collection of objects or also a DataTable if you are using ADO.NET to read the objects from a database.
Just use the TreeView.AfterSelect event. It fires anytime the user selects another node, either by keyboard or mouse. Be sure to dispose the old DGV if you replace it completely.
I have a set of data that has been displayed as just a simple GridView with the item name being a hyperlink to view details. I'm attempting to update this scenario so certain fields (sortOrder and isApproved) are editable from the main page and do not require visiting each item in the grid.
I have converted the GridView to a DataGrid and have included a TemplateColumn for the columns in question. I have them hooked up to display the values appropriately. At this point, I'm trying to find a way to peek into the DataGrid and it's related data source to determine if the values have changed on the click event of a button. At that point, I could persist those changes back to the respective SharePoint list.
I'm not very familiar with the DataGrid, or GridView for that matter. Can anyone point me in the correct direction on how I could gain access to the data source at an item/row level during a button click event?
If you add an event handler for ItemCommand, you can then access e.Item.DataItem to get at the data for a particular row.
I believe for a GridView the equivalent would be RowCommand, but not sure off the top of my head.
I needed to learn about DataGrid a while back and asked the question about some good tutorials. The post is located at: Good DataGridView tutorial
To see if any values have changed you will probably have to set a store the row id somewhere when something is changed, then go through all the rows that have changed and do your update.
I hope that helps.