I know that you can use keywords with labels, but is there any way to use a specific value from my data set as a label? What I would like to do is have a column of my data table contain a custom label string, so that each X-axis value graphed would have a unique label, but it seems there is no way to connect a series to an element from my data source. Is there a workaround to this, or will I just have to manually add labels over the chart?
I believe you are looking for setting a label for your datasource which is different from the columns which derive the X and Y values.In that case you can do this in the following manner
Chart1.Series[0].Points.DataBind(data, "XValue", "YValue",
"ToolTip=mytooltip,Label=LabelColumnName");
Here you can specify the column name against Label which would be used to display the label, in the same fashion you could also set up the tooltip from a different property.
If this is not you are looking out then please update the question with more details.
EDIT
you can set the position of the label using CustomProperties of the series
Chart1.Series[0].CustomProperties = "LabelStyle=Left"; Check this
Related
I am using a "DevXpress.XtraGrid.GridView" and I have a column there which is bound to a boolean data. This column shows check boxes to represent values. I need to show "YES/NO" instead of check boxes. Please advice me.
Thanks for helping,
Kushan Randima.
This is how I do it in code in one of my tools. This is a dynamic SQL Query tool and it returns a checkmark or red X beside the query result, at runtime. You can also do this through the designer but this is done in code.
This is for Winforms, but the low level GridView should be the same code for WPF (I am not positive).
First, in the Data Grid GridView designer, I add a column (mine is "IsError" column). Then in my form constructor or InitializeForm() I do this:
RepositoryItemCheckEdit checkEdit = gridOutput.RepositoryItems.Add("CheckEdit") as RepositoryItemCheckEdit;
checkEdit.PictureChecked = global::Gyrasoft.Common.DX.Properties.Resources.exclamation;
checkEdit.PictureUnchecked = global::Gyrasoft.Common.DX.Properties.Resources.accept;
checkEdit.CheckStyle = DevExpress.XtraEditors.Controls.CheckStyles.UserDefined;
gridViewOutput.Columns["IsError"].ColumnEdit = checkEdit;
The resources, of course, have to be valid images.
Basically you add a repository item (RepositoryItemCheckEdit) and set CheckStyle to UserDefined, and assign the checkEdit to the gridView column. You can add the same checkedit to multiple columns. It is simply for rendering or editing.
I'm looking for a C# or VB.NET solution for this.
UPDATE:
I have a RadGridView with 5 manualy defined columns by me:
AutoGenerateColumns property is set to False.
When I instace a GridViewRowInfo class I can set a lot of properties for this object:
Dim MyRow As New GridViewRowInfo(Me.RadGridView1.MasterView)
With MyRow
.Cells(0).Value = "My Value for Column 1"
.Cells(1).Value = "My Value for Column 2"
.Cells(2).Value = "My Value for Column 3"
.Cells(3).Value = "My Value for Column 4"
.Cells(4).Value = "My Value for Column 5"
.Height = 50
.Tag = New Object
.IsSelected = True
End With
And when I add that row the properties that I've previously set for that row takes effect inmediately:
RadGridView1.Rows.Add(MyRow)
If I want to add a collection of those rows just I can set a new collection of GridViewRowInfo that implements the IList interface:
Dim MyRows As New List(Of GridViewRowInfo)
MyRows.Add(MyRow1)
MyRows.Add(MyRow2)
MyRows.Add(MyRow3)
RadGridView1.Rows.AddRange(MyRows.ToArray)
Well, so my intention is to set a collection of those rows as DataSource, for example:
RadGridView1.DataSource = MyRows
So the first thing to notice is that I've set a collection of GridViewRowInfo and I've set different properties for each GridViewRowInfo that should take effect when adding the datasource-collection, the second thing is that if I update the datasource-collection to remove or add more rows then the RadGridView control should perform the updates automatically without more intervention ...not?
The problem is that any of those things happens:
As you could see in the image above, when I set a List(of GridViewRowInfo) as my DataSource, it only adds empty rows, and if I previously have set for example the Height property of one of the GridViewRowInfo inside it does not take effect when setting the Datasource:
I would like to perform this in the more direct way and the less extravagant way, I mean i'm not looking for create a custom class to be able to set that class as DataSource, and reproducing all the properties that exposes the GridViewRowInfo class or something so tricky in my custom class, 'cause If the RadGridView exposes a good GridViewRowInfo class with all that I need why I should consider to create a custom class to set it aa my DataSource?.
If I don't have a good idea or a missunderstanding of these concepts please clarify me them, I know that the usage of the datasource should not be used in that way (or I think so) but I really would like to do it to simplify the things even more to work directly with the datasource (and each row property) instead the control itself.
Also I've tried the oficial example in this link (but just using a list(Of String) instead), but it just adds a new column in my gridview named 'Length' (with a numeric data) in that column cell.
RadGridView supports two ways of populating with data:
Unbound mode where you can manually add the columns and the rows to the grid (just like you did)
Bound mode where you set the DataSource property of the control to one of the supported types, namely
Array and ArrayList of simple types or custom objects.
Generic Lists of simple types or custom objects.
BindingList or other IBindingList` implementations.
Database data using DataTable, DataSet or DataReader components from a wide range of providers (MS SQL, Oracle, Access,
anything accessible through OleDb).
So, you cannot bind the grid to collection of GridViewRowInfos (as you will only see the GridViewRowInfo type properties). You should either continue manually adding the as you are right now, or you can populate a DataTable for example with your data and set it as DataSource for the grid.
*All of the links and information are from the Telerik UI for WinForms documentation
If I don't have a good idea or a missunderstanding of these concepts please clarify them
You are confusing WHAT to display with HOW to display them which are 2 very different things. From their online guide: The RadGridView supports the standard Windows Forms data binding model which is to say the datasource provides data for the control, not presentation information.
Public Class MyObject
Public Property MyInt() As Integer
Public Property MyString() As String
...
Dim myList As New List(Of MyObject)()
myList.Add(New MyObject(1, "Outdoor"))
myList.Add(New MyObject(2, "Hardware"))
myList.Add(New MyObject(3, "Tools"))
myList.Add(New MyObject(4, "Books"))
myList.Add(New MyObject(5, "Appliances"))
RadGridView1.DataSource = myList
Result:
Note how the control automatically picks up the Property Names from the custom class: MyInt and MyString become column names. That is the only layout (HOW) related thing the grid picks up from the DataSource, and thats only when AutoGenerateColumns is True (otherwise they would be blank). When False, you control it by laying out the columns.
Now look at what you are attempting:
With MyRow
.Cells(0).Value = "My Value for Column 1"
.Cells(1).Value = "My Value for Column 2"
...
.Height = 50
.Tag = New Object
.IsSelected = True
There are many problems with this as a DataSource. Mainly, you are not supplying data for cells, but data in cells for cells. Your approach sort of mixes the unbound approach (explicitly specify what is to go into each cell), with binding to a datasource.
But, how is it supposed to know Value is a data display item? How is it supposed to know to drill into the cell collection to find Value? How is it supposed to know that Value is data but Tag is not? How is it supposed to know not to try to display Height as column data? Just because the name matches a control's property name?
What would happen if myObject by chance had a Height property related to my class? You want the control to interpret it as control layout information, but the rest of the world would want the patient's height, or building height or geo formation height to show as data. We would have to design classes with unique names not found in the control in order to get our data to show and prevent the control presentation from whimsically changing based on data and property names in the DataSource.
The GridviewRowInfo as the name suggests provides row information, not row data. Extensive presentation information is present in your List, but it doesnt work like you want because controls do not use the datasource to get presentation infomation.
The control does include Four ways to customize RadGridView appearance: Themes, UI editor, Events and Conditional Formatting.
There other elements like GridTableElement and GridTableBodyElement. Actually these elements contain some properties that control behavior and appearance of grid cells and rows, like GridTableElement.RowHeight, RowSpacing and so on.
tl;dr
Data passed in a DataSource, does not affect the presentation (aside from Column names with AutoGenerateColumns, but that is a function of that property, not the datasource.)
I'm working on a GUI that allows the user to manipulate xml files. I display the xml file in a datagridview organized neatly by columns through xml elements. I allow the user to add columns as an extention on my project. The column gets added to the dataset table, then updated to the datagridveiew that I use to display the xml file in. I've included the ability for the user to add a combobox column to select choices instead of entering them in constantly like.. true or false. However, that is where the problem lies. Saving a normal column was easy. The combobox column is being a pain.
I have a "save combobox column" to have it updated to the xml and a "save" button to save in a destination of the user's choice.
I've done some research and it seems like the combobox class has such a feature to gain access to the selecteditem in the combobox put in by the user.
Where we have:
ComboBox box = new ComboBox();
box.SelectedItem;
I tried applying this to the combobox column class but it does not have such a function. Thus, I cannot figure out how to directly obtain the value of the user's selected item. I tried experimenting with comboboxcell's as well, but that didn't lead me anywhere either. Both those classes I played around with do not have a... "selected item" function and even google does not have a solution for me. =( I've also tried using the cell.value, but it is "null" for some reason. Even when the user selects an item in the box, it doesn't get saved into the cell's value.
TLDR:
My question in short is, how, if possible, do you gain access to the comboboxcolumn cell's selected item? Additionally, how would you then ensure that the item value is saved in the cell?
Thanks in advance. I'm using .NET 3.5 SP1, through Visual Studio 2008 C#.
Sincerely,
tf.rz
The Control in a DataGridView is not a ComboBox, it is a DataGridViewComboBox and has different properties and methods. From MSDN
Unlike the ComboBox control, the DataGridViewComboBoxCell does not have SelectedIndex and SelectedValue properties. Instead, selecting a value from a drop-down list sets the cell Value property.
However, you mentioned that the Cell.Value is null for you. Well there may be another step you are missing according to the following article (How to: Access Objects in a Windows Forms DataGridViewComboBoxCell Drop-Down List).
You must set the DataGridViewComboBoxColumn.ValueMember or DataGridViewComboBoxCell.ValueMember property to the name of a property on your business object. When the user makes a selection, the indicated property of the business object sets the cell Value property.
If we have bound a datagridcomboboxcell with a different DisplayMember and ValueMember, like so:
dgcombocell.DisplayMember = "Name";
dgcombocell.ValueMember = "Id";
dgcombocell.DataSource = dataset1.Tables[0];
Then for getting SelectedText, and SelectedValue, we can write this code:
string SelectedText = Convert.ToString((DataGridView1.Rows[0].Cells["dgcombocell"] as DataGridViewComboBoxCell).FormattedValue.ToString());
int SelectedVal = Convert.ToInt32(DataGridView1.Rows[0].Cells["dgcombocell"].Value);
I hope it solves your problem.
Use this to get or set selected value:
object selectedValue = currentRow.Cells["comboboxColumnName"].Value
Don't forget to set DisplayMember and ValueMember for your DataGridViewComboBoxColumn
This is how it is done
DataGridViewComboBoxCell comboCell = (DataGridViewComboBoxCell)dgv.Rows[0].Cells[1];
MessageBox.Show(""+comboCell.Items.IndexOf(comboCell.Value));
A .Net combox is actually a composite control made up of a textbox and a dropdownlist. Use box.Text to get the currently displayed information.
EDIT: The row or the cell should have a .FindControl() method. You'll need to do something like:
Combobox box = (Combobox)(row.FindControl("[combobox ID]"));
string val = box.Text;
Basically, you're finding the control within its container (row or cell), then casting the control found as a combobox, then accessing its .Text property.
I use this:
private int GetDataGridViewComboBoxCellSelectedIndex(DataGridViewCell d)
{
return ((DataGridViewComboBoxCell)d).Items.IndexOf(d.Value);
}
I have a DataGridView in a C# WinForms app that is DataBound at runtime (through Form_Load) to a custom Object.
In the design view of the DataGridView I have no columns set up.
When the Form loads the the columns are automatically created based on the data in the Custom object that it is DataBound to.
My question is how can I control the the Columns that are automatically created.
For example if I want one of the columns to be a DataGridViewLinkColumn instead of the DataGridViewTextBoxColumn that is automatically created?
The default columns are based on the data-type. I haven't checked, but for a link you could try exposing the data as Uri, but that might be hopeful. Really, if you want a specific type of column - add the columns through code and set DataGridView.AutoGenerateColumns to false.
As Andrew implies; normally something like reflection is used to generate the columns, and you'll get a column for every (browsable + public + readable) property. There is a layer of abstraction on top of this if you need, but this won't help with adding a hyperlink column.
You can pre-create your columns in the designer. If the name of the column matches the name of the property the column will end up bound to, the databinding will take care of the DGV population for you as before.
Edit 1
I believe my problem stems from the following. The function that fills the dropdown portion sets the Display Member to the CountyName. Then when I try and set the SelectedText or EditValue, as has been suggested, that function only returns the CountyID which it try's to match to something in the DropDown list DisplayMember. I need it to match it to something in the ValueMember list.
Using the following I got it to work but it is a HACK and I'd greatly appreciate finding a real solution.
lkuResidenceCounty.ItemIndex = Convert.ToInt32(row["ResidencyCountyID"].ToString());
Original Post
I have a lookup box(DevExpress) on a member form that I fill the possible values in from the DB with this code -->
lkuResidenceCounty.Properties.DataSource = ConnectBLL.BLL.Person.CountyList();
lkuResidenceCounty.Properties.PopulateColumns();
lkuResidenceCounty.Properties.DisplayMember = "CountyName";
lkuResidenceCounty.Properties.ValueMember = "CountyID";
lkuResidenceCounty.Properties.Columns[0].Visible = false;
lkuResidenceCounty.Properties.Columns[2].Visible = false;
lkuResidenceCounty.Properties.Columns[3].Visible = false;
This works just fine as the CountyName is displayed as expected.
However, When I try and load an existing member's value for this field using the below, which is part of a function that takes a row from the DataSet -->
lkuResidenceCounty.Properties.ValueMember = row["ResidencyCountyID"].ToString();
I get a blank box. I have stepped through the code and the correct ID is being returned for the member.
Unfortunately the stored procedure to fill the dropdown options pulls from a Maintenance Table with the columns "CountyName" & "CountyID". So that is correct. Unfortunately, the stored procedure to load a specific person's current county pulls from the Person Table where there is a column called "ResidencyCountyID". It is so named because there is also a "ResponsibilityCountyID" column.
I need a way for them both to coexist, any solutions?
Thanks!
DisplayMember and ValueMember are used to populate the control with the list of selectable values. To set the selected value of a populated LookUpEdit control, set its EditValue property:
lkuResidenceCounty.EditValue = row["ResidencyCountyID"].ToString();
In response to your edit: According to the documentation:
The currently selected row determines values for the editor's edit value and display text. The value for BaseEdit.EditValue is obtained from the RepositoryItemLookUpEditBase.ValueMember field, while the text to display in the edit box is obtained from the RepositoryItemLookUpEditBase.DisplayMember field of the selected row.
When you change BaseEdit.EditValue,
the editor locates and selects the row
whose
RepositoryItemLookUpEditBase.ValueMember
field contains the new value. The text
in the edit box is changed to reflect
the newly selected row.
I don't use these controls but it sounds to me that it shouldn't be working as you described. I think the ToString() is the problem because EditValue accepts an object so it's probably expecting an int for the value. Try:
lkuResidenceCounty.EditValue = (int)row["ResidencyCountyID"];
The ValueMember property tells the list what field to pull from when setting the Value property. Once you've set the ValueMember to "CountyID", then when the list is Databound, it will set all the list items' value properties to their respect objects' CountyID fields.
Hence, you should not do:
lkuResidenceCounty.Properties.ValueMember = row["ResidencyCountyID"].ToString();
but rather
lkuResidenceCounty.Properties.ValueMember = "CountyID";
was perfectly fine, as long as you've correctly identified the field you're trying to databind. Once the list get's databound you should see the results you're expecting.
However, after looking at your code, it seems that you're mismatching your field. In one place you're using ResidencyCountyID and in another you're using CountyID. That is most likely your source of confusion. Figure out what the actual field name is and make sure you set the ValueMember to that.
UPDATE
After reading your comment, what your looking for is the SelectedValue property. The SelectedValue property tells the list to force the selected value to whatever input you give it.
Essentially you have two things going on here. ValueMember tells the list what to use as the value from your data source, and SelectedValue which tells the list what the currently selected value should be.
Why is it that you need the same LookUpEdit to have two value members? Is it being used standalone or in a grid? If standalone, you could swap out the two repository editors depending on the current row. But, are there more than 2 possible values for the ValueMember? That would also complicate things.
UPDATE
Looking at your edit, I think I understand what's going on a little more. So, you don't wish to change your ValueMember (which refers to a data column), but rather to change the value of the editor? If so, then you should definitely use EditValue (not SelectedText, which I don't believe is meant to be set), and assign it to row["value_field"] like so:
lkuResidenceCounty.EditValue = row["ResidencyCountyID"];
What happens when you do that?