I have a Radgrid with column that can has a 2 values: YES or NO. Value is presented in label and when I doublcick on this cell, it changes into combobox, so user can choose from yes or no. Now, I want to achieve something like this: when I set one row to YES i want all other rows set to NO. So it will be always only one row with value YES. I hope you understand me. How to do it?
Here is how to loop through the items and access them http://www.telerik.com/forums/loop-through-rows-of-radgrid-and-retrieve-cell-values
Another option is, since each row is a data item, to modify the datasource accordingly and Rebind() the grid.
Related
I have a Datagridview and 18 comboboxes.Each combobox represents a column of the Datagridview.
The point is: when I select a combobox item in the dropdownlist, I'd like the other comboboxes to select the corresponding item. I believe that to do that I have to make the comboboxes remember the row of the item.
At first I tried to make a specific class for it but I'm having some trouble.
Then thought that I could store the row information into the combobox by putting it into value property. But I'm still having troubles.
Keeping in mind that trouble won't ever completely leave me, someone has any tips?
Thank you all so much.
I would try this: use the SelectIndexChanged on the first combobox and get the line index, after that, change the others combobox index by setting them with the index you found. This is the dumbest approach, then you can improve it.
well i have worked with datagridview now i need to work with a listview i dont know how to select the value it has in one cell..
my another option is when a cell was added or deleted, all this information is on datagridview
but it doesn't have a (datasourcechanged) then how can i anyone of these?
I tried secund with this code:
DataGridView1.DataSource = lvDevices
so i could select anyone but i need when in datagrid changed its value, it passed to datagridview well my another way is
how can i select the value of one cell in a ListView?
you could try this in this listview1_doubleclick event. ...
string a = listView1.SelectedItems[0].SubItems[column index corresponding selected cell].Text.
Using C# & asp.net
if there is no data's in the table, gridview displaying one rows (it was empty)
I want to hide the gridview empty row.
How to do this.
Assuming that you can normally delete that one visible row just check that if a field that would normally have a value is empty and the row count is 1 then delete that row.
if(String.IsNullOrEmpty(mydatagrid.Rows[0][0].ToString()) && mydatagrid.Rows.Count==1) //Check a field that would normally have a value
{
mydatagrid.Rows.RemoveAt(0);
}
Let me know if this helps/works
If you are manually data binding than you can check at that time and hide or disable the control if there is no data. If you are data binding using the design view than you should subscribe to the DataBinding or the PreRender events on the control and check then.
you can check if the datatable doesn't have any rows
use:
mydatagrid.DataSource=null;
mydatagrid.DataBind();
As the other two comments you can either check in code and set MyDataGrid.Visible to true or false to hide the entire table, or you can not bind the datasource, or you can EmptyDataTemplate option to display whatever you want when there is no data for the GridView to display normally.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatemplate.aspx
The normal behavior for GridView is to render NOTHING if there are no data rows. (Well, almost nothing; it insists on rendering a <div> wrapper, but that'll be empty.)
If you specify an EmptyDataTemplate, however, a one-celled wrapper table is generated to contain whatever is in your template. Even if your template is empty, you'll get that wrapper table (with its one cell, empty). Sounds like the answer to your question is don't specify an EmptyDataTemplate.
I am working with a DataGridView and have a column of type DataGridViewComboBox and I have stumbled across a problem. Basically, depending on the value of the cell, i would like to set the .Items to a certain set of strings, but when the value is changed, i would like to change the .Items list. But with this, I will occasionally remove a string from the list that is currently being occupied by another DataGridViewCell, this changes all the values that were equal to the removed item, until i re-add it back to the list (after i have finished editing).
So basically, I am wondering if there is a way of hiding some of the items from the combo box Drop Down list, so that when a certain cell is selected, they can't choose an item that isn't allowed.
Thanks,
Lloyd
Instead of databinding the entire column, databind each row's DataGridViewComboBoxCell individually. That way, you don't have .items from one row affecting .items from another row.
I have a typical requirement.
I have a datagridview with a combobox column(items loaded at design time). When a user selects an item from combobox, remaining rows gets updated in database based on the selectedItem and dgv gets refreshed.
Problem is the combo box will lose its current selection and goes to unselected state.
I want to retain the selected item even after dgv refreshed.
Could anyone help me out
Thanks in advance
Do you mean that you're using an unbound comboboxcolumn? If so, the value can't automatically be persisted when refreshing the datasource. You need to store the selected value before updating and setting it in code after refresh.
If your column is actually databound, the selected value is either not stored in the database or you have some data type problem.
Is the combobox there to let the user select a value for the field or do you use it as a way to execute a command on the record?
Do you have any code you can post?
Datagrid Combo-Box value will retain the string value but will refresh any integer values automatically.
Here is what you need to do :
-When populating Combo-Box value to just convert its value to toString().
-Also if you are setting a default select value also set it with string type.
-Your Combo-box will automatically retain the value selected even after refreshing.
:)
have a combobox in ur datagridview. Assign values to it using a bindingsource.
then write an eventhandler for the datagridviews "EditingControlShowing" event.
in that, remove had handler if any exists for the comboboxes Selectedindexchanged event. then add an event handler for the selectedIndexChanged event say "ComboBoxValueChanged"
in that "ComboBoxValueChanged",
DirectCast the sender to System.Windows.Forms.DataGridViewComboBoxEditingControl and get the selected value of it.
Now use it to compute any value you want.
you may wana refer to this
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxeditingcontrol.aspx