Update column headertext in c# window app - c#

In the search form by display button records are displayed from database. but i wnt to
change the header text of data grid column like member_id as memberID.
how can i do it?
as i m trying datagridview.column[1].headerText="memberID" it shows error of indexes of collection so what code i will use to change the header text?

try grid.Columns[0].HeaderText = "memberID". Your column indices may be running out of bound.

Related

How to change the value of a Text Box depending on the currently selected row within a Data Grid?

Hi I'm hoping someone can help,
I have a Data Grid that has X amount of rows and I have a Text Box at the bottom of my form called 'Notes', I want the user to be able to select a row then enter a note within the Text Box and store this so when the user selects a different row the Text Box will be blank available for notes to be added for the new row. Then if the user selects a row that they have added notes to the Text Box will contain those notes.
I hope that makes sense, any ideas on how to approach this would be really appreciated.
Thanks,
Ryan
Thanks to GuidoG I have solved this, just in case anyone else has the same issue what I did was add a data binding to the grid then set the parameters. "Text" is just the property name, MyDataTable is the data source for my grid and "Notes" is the column name.
MyGrid.DataBindings.Add(new Binding("Text", MyDataTable, "Notes"));

after updating dynamic gridview in asp.net it is showing multiple values in each row why

here i am going to update multiple values at a time by using single button click
On clicking update button for gridview it is showing multiples values for each and every column
After refreshing the page it is showing normal data
For example if i am inserting 1 in 1st column, 2 in 2nd column after updating gridview it is showing 1,1 2,2 like that
Because your gridview has autogeneratecolumn = true. change to false.
Or if you want custom header name do this steps:
in gridview property (Design part) click edit columns -> your boundfield -> under its property, you can see the "DataField", set your field name of your database. You can see now the data of your records from your database. also you can set header name.

How do I start the program off with multiple rows on a DataGridView?

I don't know think I wrote any code for this since the properties are all default. I don't want the user to have to add those by themselves when it is in the middle of the run.
It lets me add in columns but not rows in the designer.
Is there any property that can start the program with more than 1 row in the data grid view?
Populating the grid with data must be done with code. If you populate the grid in the Load event handler then the user will see that data when the form is displayed. You can add data directly to the grid or you can populate a DataTable or some other list and bind that to the grid.
If you're saying that you actually want multiple blank rows in the grid then you need to add those rows. The row you see by default is not actually part of the data of the grid. It's just there to indicate to the user that they can enter data.

Getting DataGrid row details

I have a quick question regarding getting a specific value from a data grid, say I've got 4 columns, id surname, firstname and phone number. I want to get the ID From the selected row that the user has currently selected ? how would I go around this, I've tried several attempts but it's just returning the whole row rather than the single ID.
Thanks again
Rolls
((class)yourGrid.SelectedItem).ID
In "class" put class of your object stored in grid.
If you know the index of the id column you can get DataGridCell using code at:
Programmatically edit a datagrid cell in wpf
Then you can get ID by getting DataSource for DataGridCell.

How to add a new row into datagridview using grid only. i.e by showing textboxes and add button in WinForm

I want to add a new row to a datagridview such that when a user clicks on new button , a new is is generated with few textboxes and combo boxes and after filling up all the details he save the info by clicking on save button.
EDIT
I want to do it like it is seen in gridview(Template Fields) in asp.net
I am looking for same kind of functionality.
Since I'm not sure exactly how you want to achieve this.. I would have a hidden panel with your text boxes, ...etc, show the panel when the new button is clicked. After all information is entered into the fields, click the save button. Assuming that you will be inserting this information into a table, after the row is inserted, call the stored procedure to get the desired records from the table being displayed in the grid.
Assuming your _dataGridView.Columns collection is not null and contains a template of the rows you wish to add, it is as simple as something like this:
foreach(var item in _collection)
{
_dataGridView.Rows.Add(item.Foo, item.Bar);
}
In order for this to work, you will have had to design your Columns collection in the VisualStudio designer or programatically add DataGridViewTextBoxColumn objects to the Columns collection.
In the example above, I added two DataGridViewTextBoxColumn objects to the _dataGridView.Columns collection and then populated the datagrid from a List of my object that contained a 'Foo' and a 'Bar'.
EDIT
Have you checked out the DataGridView FAQ? The information about using the DataGridView in unbound mode may help you.
HTH

Categories

Resources