I need to set a static width of a bar chart series using dotNetCharting. My Graph has three series collections of line, spline, and column type. I would just like to set a static width for all series of column type.
I've tried using:
myChart.DefaultAxis.StaticColumnWidth = 10;
But the .DefaultAxis property isn't valid in intellisense for the whole chart nor the Column series collection. Do the series have to be added with data first before setting this?
Also, I've tried adding properties in the series object, no luck.
Any ideas?
series["PixelPointWidth"] = "your value for width";
part of chart series collection: a custom property
chart1.Series["Series1"]["PixelPointWidth"] = "1";
Related
I am using a VS 2012 Windows Forms datagridview control. The datasource for the grid is a JObject but I have one predefined column that is supposed to display data from one of the datasource cells, which is also a JObject. After the datasource is assigned to the grid, I loop through the rows and add the new values. But it doesn't work quite right.
for (int i = 0; i < dgv.RowCount; i++)
{
JObject account = JsonConvert.DeserializeObject<JObject>(dgv.Rows[i].Cells["incomeAccount"].Value.ToString());
dgv.Rows[i].Cells["account"].Value = account["accountName"];
}
This console output actually shows the correct text, for instance, "John Smith". Howver when the grid is finished loading, the cells in that colunm are all blank. The datagridview column is not read only. Is there something else I need to do to get the new data to appear?
DataGridView likes data binding. Create an array of objects that have the properties you want to see, and then set that array to your DataGridView.DataSource property.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource(v=vs.110).aspx
The grid has to be the active control to update cell values after databinding. Calling dgv.focus() before the for loop fixed my problem.
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 using a Microsoft chart control and binding a DataTable to it using Chart.DataBindCrossTable One of the parameters is a string called otherFields and you can specify any property associated with a Point in that string:
chart.DataBindCrossTable(table.Rows, "COLUMN1", "COLUMN2", "COLUMN3", "Label=COLUMN4, LegendText=COLUMN1, ToolTip=COLUMN3");
I wan't to specify multiple columns in the ToolTip field, something like:
ToolTip=COLUMN3 = COLUMN4
so that the tool tip for each point would be "COLUMN3 = COLUMN4" where column3 and 4 would be filled in with whatever the values were in those columns/rows for that point.
But when I do this I get an error saying that there wasn't a column called "COLUMN3 = COLUMN4" in the datasource. How can I make this happen?
You could create another calculated column in your datatable to display what you want and bind to that.
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
I've noticed that every control added to the TableLayoutPanel is given "Column" and "Row" properties.
How can I get access to these properties through code?
thanks:)
These properties only exist in the Properties Window, magic provided by the IExtenderProvider interface. They don't exist at runtime. Extended properties are:
ColumnSpan. Runtime: GetColumnSpan() and SetColumnSpan()
RowSpan. Runtime: GetRowSpan() and SetRowSpan()
Row. Runtime: GetRow() and SetRow()
Cell. Runtime: GetCellPosition() and SetCellPosition()
Column. Runtime: GetColumn() and SetColumn()
Obviously TLP was highly optimized to be used from the designer. It's kinda of a pain at runtime.
Although the properties designer shows the row and column as properties of the added control thay are set programatically using a method on the table layout panel itself (SetColumn(control, index) and SetRow(control, index)).
This pattern of behaviour is similar the tool tip component and the error component.
Go here.
This properties are added by means of "extending properties", something that other controls like ToolTip uses.
// Create TableLayoutPanel
TableLayoutPanel tlp = new TableLayoutPanel();
// Set the BorderStyle to Inset
tlp.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
// Grid has two columns
tlp.ColumnCount = 2;
// Grid has two rows
tlp.RowCount = 2;
// If grid is full add extra cells by adding column
tlp.GrowStyle = TableLayoutPanelGrowStyle.AddColumns;
// Padding (pixels)within each cell (left, top, right, bottom)
tlp.Padding = new Padding(1, 1, 4, 5);
// Add TableLayoutPanel to the Forms controls
this.Controls.Add(tlp);
for more check this
http://en.csharp-online.net/TableLayoutPanel