ListView how to select the text inside a cell? - c#

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.

Related

ComboBox in DataGridView WinForm not rendering selected value

I have a weird problem with ComboBox Column in DataGridView in WinForm.
When I select the item from ComboBox, the selected value would not be rendered by the ComboBox. I need to click the ComboBox so that the selected value of the ComboBox would be rendered or displayed. If not, the ComboBox would just display empty.
The weird thing is this only happen in my first ComboBox Column in DataGridView.
In other words, this issue is not happening with my Second, Third or etc ComboBox Column in DataGridView.
Any ideas? Could it be a DataGridView bugs?
Thanks for your attention.
Thanks for your attention.
I manage to find the solution for the question that I have asked.
Overview:
I populate rows in DataGridView manually by adding row into DataGridView.
For DataGridViewComboBoxCell object, I use DataSource to populate the Items instead of adding the Items manually to the
ComboBoxCell.
The Problem:
Whenever you select the item in ComboBox, it is unable to render the selected value in the ComboBox. It would only show the value if you click it.
Solution:
It turns out in the code somewhere after I set the DataSource of the DataGridViewComboBoxCell, I called its method, DataGridViewComboBoxCell.Items.Count. This is the source of the weird behaviour.
Somehow, if you have set the ComboBoxCell DataSource, and you call Items.Count method, it would show that weird behaviour.
I should not use Items.Count since I am using DataSource. The Items.Count would always be zero because the DataBinding it's not happened instantly the moment you set the DataSource.
Hopefully this post would help someone else in the future. Thanks.

Changing Radgrid value changes other

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.

How to add a single combobox into a datagridview in random positions

I want to add DatatGridViewComboBoxCell into dynamically determined cells onto the datagridview.
So far all of the examples I have found either make the entire columns' cells into comboboxes or don't work.
Here is the simplest example that I can come up with. I have tried databinding to sources which work to a point. The items exist in the combobox.items but on the datagridview the combobox is empty and you cannot select a value
DataGridArticles.Columns.Add("columna", "columna")
Dim combo As New DataGridViewComboBoxCell
combo.Items.Add("b")
combo.Items.Add("ba")
combo.Items.Add("ca")
DataGridArticles.Rows.Add()
DataGridArticles.Rows(0).Cells(0) = combo
Is it possible to add a combobox to a specific cell in a datagridview.
I've never had any problems with DataBound DataGridViewComboBoxCell.
I'm using it like this:
Dim cell As New DataGridViewComboBoxCell()
cell.DisplayMember = "Name"
cell.ValueMember = "Id"
cell.DataSource = list
DataGridArticles.Rows(0).Cells(0) = cell
cell.Value = 0 //It will select and display item with Id = 0, if you do not set it
//then combobox will look exactly like yours on image posted (like
//there is no items in it).
It worked flawlessly every time I used it. So if it does not work for you may.
So to fix your problem add this line after adding items to combobox:
combo.Value = "b";
Hope it helps :)

How to clear data in DataGridView?

I am new to C#. How to Clear data in DataGridView?
I have some data in datagridview and I have one drop down box at every index changed
I want datagrid view will be changed. but I did not get the solution just i Added to
previous data can any one help
if you use data source to fill the grid use:
dataGridView1.DataSource=null;
dataGridView1.DataBind();
if you fill the grid programmatically use:
dataGridView1.Rows.Clear();
If you want the DataGridView change when the Dropdownlist change so u just reuse the Code grant value to Datagridview.

Method to find DataGrid Row is selected or not?

I am new to C# and WPF. Issue I have is on datagrid I am displaying datatable data. I need to update data based on selected row. I am able to achieve that.
However, when I do not select any row on datagrid it does select default row as '0' and I do not want that I want result as -1 or error because I have not selected any row there?
You can determine if a row is selected with dataGrid.SelectedIndex; if the value is >= 0, you have a row selected.
To access the selected row:
if (dataGrid.SelectedIndex != -1) {
YourDataType row = (YourDataType)dataGrid.SelectedItem;
// process stuff
}
In the event that you allow multiple selections in your data grid, a very reasonable assumption, you can access the collection with the dataGrid.SelectedItems property.
A similar answer that shows example XAML too can be seen here: Get selected row item in DataGrid WPF
Not very clear about what actually you wanted to do. Just set yourdatagrid.SelectedIndex=-1; in some sort of initialization part of your code.

Categories