VB datagrid + array with custom class - vb.net

I have created a class "student" and made an array which contains students.
I would not only like to display the array in a datagridview, but the array should also be updated if the user makes changes to one of the students in the datagridview.
I succeeded in showing the array in the dgv: one way is using datasource prop, the other is doing is diagrammatically. However, i can't find out how to let the user edit the array by editing the dgv.
Anybody know how to do this?

If the grid is not read only,and the data is bound from the datasource property,any value displayed should be editable if you double click it

Related

Hidden model-bound values in view not getting passed to controller when populated manually

I'm using the KendoUI AutoComplete for a number of look-ups on a custom editor template that pop-ups off a grid for new rows and edits. The Kendo AutoComplete does have a DataTextField property and does not DataValueField property like a DropDownList would. So, I found I am able to get the Value of the selected item in the AutoComplete with a little Javascript and iterrogating the "dataItem" object in the select handler. And I put that value into a "SelectedID" field declared with #Html.HiddenFor(model => model.SelectedID) on the select event.
Now, when I do a save from the view and have a break point on my controller action that captures the incoming model, all those ID values where i set the value manually are empty/null/blank. I've checked the DO and have done "console.log" to read out the values of the hidden fields before the post and the values are populated. I've changed the datatypes (strings, guids, etc) and I've changed the Html Helper type as well from a HiddenFor to a EditorFor just to make sure the values are indeed there.
So i think this is a problem when the values of an element that are part of the model are populated in a "manual" fashion. The text of the AutoCompletes comes through if I bind that to a field on the model as well. Any date fields, checkboxes and free-form text fields come through as well. It seems it is just values of model bound fields where I set the values manually that don't make it over the "wire". Any thoughts? Solutions? I know the Selected Value is accessible ... it's just a matter of properly getting it into the "HiddenFor" fields.

Textbox databinding to 2 properties

I have a form that saves to an order data table. A few of the fields in the form are linked to a table that contains customer names and address details. The shippername field in my order data table is a combobox - you select the name and the corresponding address information for that name is displayed in textboxes that belong to the address, city and phone number fields for my order datatable. For that, I am using the databinding property of the combobox control for that field, and using the Text property for the textboxes (binding to the source table, which I call shipperdata.) When I run the form, it displays the information I want.
The problem: when I save the form, the names of the shippers are saved fine. However, the other fields related to the shipper name are not. I realized that the binding property would not let me bind the contents of the textbox to my order datatable.
I went into the designer and thought I'd try an experiment, thinking that if the combobox can bind to a source and bind the text to the order datatable, I should be able to do that with a textbox. Right? Apparently not so much. Here's what I tried:
'Shipper1address1TextBox
'
Me.Shipper1address1TextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.ShippersBindingSource, "SHIPPERADDRESS1", True))
Me.Shipper1address1TextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.OrdersBindingSource, "shipper1address1", True))
Me.Shipper1address1TextBox.Location = New System.Drawing.Point(188, 429)
Me.Shipper1address1TextBox.Name = "Shipper1address1TextBox"
Me.Shipper1address1TextBox.Size = New System.Drawing.Size(200, 20)
Me.Shipper1address1TextBox.TabIndex = 32
I got an error saying that I couldn't bind 2 properties.
The funny part: the form is actually 'details' so I decided to drag a datagridview next to what I already had set up to see how it looked. In detail view, you'd think the data was being saved correctly to the orders data table. But, when I looked at the table in gridview, the values for the address and phone, etc were not written there. Then i reminded myself that it's only bound to the shipper data table.
My question: how can I save the corresponding address and phone information to the order table while still binding to the source so it displays? If I make the binding property to the orders data table, that's great...except now it doesn't display address information. Is there a method to accomplish this with a textbox? I'm also guessing at this point that messing with the designer is probably not a great idea. Maybe an alternative? It just seems odd that the value contained in a textbox from a data table isn't saved.
Thanks for having a look.
You can only add one databinding to each text box.
You are adding two in your code.......
Me.Shipper1address1TextBox.DataBindings.Add
ArronG.

Create custom SelectedIndices collection from existing SelectedRows collection in datagridview

I need to write a custom collection where it will store the selectedindices of the datagridview. Sine we have SelectedRows colllection property already present in Datagridview. I want to use it and get indices collection so that I can I can create SelectedIndices as a custom property for my Datagridview which is of type collection. Can some one help m eon how will I do it.
For reference;
Selectedindices is a property of Listview provided by microsoft.I want the same with Datagridview. But since I don have that I want to use the SelectedRows property and an create a custom property Selectedindices for my datagridview. It should be of type Collection. PLease suggest if I can do the same .
I do believe that feature is already available, maybe you can find out more by view the link below?
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewselectedrowcollection.aspx
Also a little code sample of how far you got, or what you have tried already always entices other members to be more helpful.

Duplicate a DataGridView on a second windows form

I have a bound DGV that took a bit of work to get its columns set up. I'd like to show a 1-row version of this identical DGV on a second windows form. Is there a way to programatically place a copy on the second form. I would adjust the height and position of the 1-row version, and create a new binding source on the second form so that I could filter the data.
MyForm.Controls.Add(myDataGridView)
So further explanation:
In your first for you will need to make a variable or property that contains a reference to the DataGridView that you want to access.
I'd suggest doing something like this.
Public Shared Property myDataGridView As DataGridView
then after you get it set up in the form the way you want it set up
myDataGridView = originalDataGridView
Then in the second form
SecondForm.Controls.Add(FirstForm.myDataGridView)
Will add the DataGridView exactly as it is on the first form.
Edit
If you are creating it in a designer, you can just either copy and past it from the original for to the second form.
Or just on the Form.Shown or in the New() of the first form set the myDataGridView to the DataGridView that you created.

Getting selected item from combobox itemrenderer and storing in object

I have a combo box itemrenderer in datagrid column. I want to get the user selected item from the dropdown of the row(s) (User may select values from combo box from multiple rows of datagrid) and corresponding values of all other columns of the rows and store it in an object . Then pass this object to database to update only those rows that user has changed.
I am able to get the selected item from combo box using "event.currentTarget.selectedItem" and corresponding values of all other columns of the rows using "valueSelect.ID", etc where valueSelect is object which contains data for datagrid. But am stuck with, how to store the selected item value of the combobox and corresponding values of all other columns of the rows into an Object?
I am seeking sample code to store selected item from combobox and its corresponding values of all other columns into an object which I can send to db.
If you're using Flex, you can bind the selectedItem property / object of the DataGrid to an Object (of the "type" used to render the ItemRenderer).
Or you can do it manually, store a reference to that object by declaring an Object (or some specific type) and then updating that value whenever a selection occurs.
So for example :
[Bindable]public var selectedItem:Object;
...
public function onComboBoxChanged(evt:ListEvent):void
{
selectedItem = dataGrid.selectedItem;
...
// comboBox specific logic here
...
}
That or, if you need something complex, possibly check out this post for a custom item renderer :
Flex DataGrid with ComboBox itemRenderer
Hope that helps!