UserControl in a DataGridView in Windows form - windows

Looking for an example of a usercontrol in a datagridview row using Windows forms.
The Usercontrol would have multipe controls based on the business logic which depends on the the index of the row.
Thanks

You cannot insert a user control directly into a row in the way you would like. Your only possiblity is to add a new column type. Your custom column implementation would act like the other columns in that when it enters Edit mode it can create a control (in your case an appropriate one for the index number) and then have it work inside the cell until the Edit mode is exited. The issue would be drawing the cell when not in Edit mode.
You can see the source code of the builtin columns by using the .NET Reflector tool or search the web for custom DataGridView columns as there are many implementations that give sample code you could use as a starting point.

Related

add textbox row below header gridview to use as filter

I have seen at times, datagridviews using an extra cell placed right under the Header of the column, as a filter for the values in the specific column.
I know it is possible to do so through a templatefield in ASP but I need to alter a desktop application using a DataGridView to display the data.
Does anyone know how to add a filter row to the grid in a vb net desktop application?
If I place a textbox right below the header row of the grid, I will hide the first row of data and I want to avoid this; if I place a textbox somewhere on the form, it looks pretty tacky.
Thank you for any suggestion.

DataGrid column header with a text box for filtering

I'm having a bit of problems creating a DataGrid with a header label AND a text box (at this point I'm not even entirely sure this is possible).
Here's what I want to do:
I need to dynamically create a table (the number of columns can and will change, so the grid needs to be created dynamically and cannot use bindings specified in the XAML code or similar). All the columns however will always be text columns.
Because those will be text columns, I'd like to add a text box to each header to enable simple filtering of the data in the DataGrid. I don't want to add extra text fields to OTHER parts of the Silverlight page, as I want to keep things as compact as possible. Also, since the number of columns is dynamic, adding a large number of text boxes above the DataGrid wouldn't look too good either. ;)
Also, if possible, I'd like to keep a label in each header to display the names of the columns as well.
So far I've tried adding the a TextBox as the Header of a DataGridTextBoxColumn but when I do that in a very simple Silverlight project, the whole DataGrid won't show up.
Please help.
EDIT:
I saw the answer to this question: placing a text box inside the silverlight data grid column header
However, the answer itself didn't give me much to go on (the example is too short, and I'm not too good with XAML yet), and the code on CodePlex just adds extra fields to the Silverlight page. None of it tackles the problem of dynamically creating the DataGrid.
OK, here's what I did that solved my issue...
I had to use a Style to achieve the functionality of having an extra text box inside each column header and filling out the Tag property of each thus created TextBox to later find out which column has been changed.

jqGrid using radio buttons for editable rows

I'm currently using jqGrid and ASP.Net MVC. With my current project, my goal is to provide a grid of data to the end user, and they can then edit this. The data is machine-generated, and the users will be confirming if the machine is correct or not.
I think ideally for speed, I'd like to provide a row per item, with a radio button group as the editable. The users could then pick from the values 'Unknown', 'Correct', 'Incorrect'.
As there will be a lot of data, I'd also like to provide a control of some type that can set all rows in the grid to one of the available radio button choices, for the user experience.
Given that there seems to be no native support for this in jqGrid, I wanted to ask if anyone has had any experience writing something like this, and whether this is achievable and reliable, or whether I should stick with the drop-down editable approach that is native to jqGrid.
To implement radio button as the editable instead of the standard drop-down editable approach you can use so named custom editing feature of jqGrid (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules#custom). This allows you to create any custom control to edit the cell value. An example of the implementation you can find here: Add multiple input elements in a custom edit type field.
To set all rows in the grid to one of the available radio button choices you can use either a control outside of jqGrid or add an additional custom button in the navigation bar (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_buttons). If you search for navButtonAdd you will find a lot of examples how to implement this, for example, Jqgrid: navigation based on the selected row. Because you use server based data, you can just call a method on the server to make the changes which you need and then call trigger("reloadGrid") to refresh jqGrid data.

ComboBox in windows forms Datagridview control

I have a datagridview on a windows form. It has clolumn [EmployeeNumber, EmployeeName and EmployeeDepartment].
I want to be able to edit values directly in the grid but i want EmployeeDepartment to be a combobox column, such that on cell edit, a combobox shows up with available options for the employee department. Has any one been able to implement such functionality?
The DataGridView actually has a DataGridViewComboBoxColumn. If you go to the column designer, and add a new column you'll notice you can select one of a few types. It behaves exactly as you have described - on edit, it appears. The DataGridView uses things called editing controls, and has various events for swapping the control into the cell on edit.
Either way, if all you want is a drop-down, that's available out of the box.
To populate the combo box with items, in the column editor you will notice that it has an Items property for manually setting items, or you can use the data binding properties: DataSource, DisplayMember, ValueMember. Data-binding has issues when an expected value is not in the items collection, you will get a lot of cell errors; but they can be avoided.
Some helpful links:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx
http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/e8e2d9eb-fe39-42ab-9a18-2194dac54675/

MS Expression Blend: Sketchflow - Populating a sub datagrid with data upon selecting a specific row of a master datagrid?

I've recently started using Expression Sketchflow to prototype some user interface designs. I currently have a master datagrid at the top of the page, which I would like to allow the user when selecting a particular grid row to see a sub-datagrid below be populated with specific data relevant to that specific row of master data.
Could anyone shed some light on the subject!?
Help greatly appreciated.
I figured out how to do this by reading this article:
Expression Blend 3 – secrets of working with data.
Here's the basic steps (you already did a couple it sounds like)
Create your sample data set
Under the Data tab select the List Mode and drag your collection onto the screen, a list view of your data will be created (Master datagrid)
Now, select the Details Mode and drag and drop your collection onto the screen where you want the details to be displayed. (sub datagrid)
Tweak the fields displayed by dragging properties into the respective containers or modifying the XAML / Bindings list
If you have a child collection in your data, you may have to jump through a few more hoops.

Resources