Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All
I am using Visual Studio 2010 Express.
I have a C# WPF appication where I have a DataGrid that I have managed to bind to a MySQL database - that part was easy!
From Code Behind, I now wish to manipulate certain rows and columns of the grid, depending on the content of cells. How can this be done?
I have found several tutorials on how to use a DataGrid, but it looks like they are for VS2008, and there have been major changes in how VS2010 uses a DataGrid, and so a lot of the functionaility is different, and I carnt find out how to manipulate a DataGrid now.
Do you know of any VS2010 tutorials that can help me?
Is DataGrid the best way to 'look' at a database in WPF - are there alternatives?
Do I need to use a WPF toolkit to provide me with a different grid control, that can be easily manipulated? If so, which is the best free \ cheap toolkit to do this?

Thanks in advance for any advice - look forward to some tips!

Mike
Posted
Comments
KM Perumal 12-Apr-13 6:13am    
You can Try ListView

AAAGGGHHHHH
I have found I was making a mistake! I was not trying to alter the properties of the daatGrid, but alter the Grid that I had place the DataGrid in, hence why I was struggling. Beginner mistake.
Thanks for your time though - sorry for wasting it!
Mike
 
Share this answer
 
Try this http://wpftutorial.net/DataGrid.html[^]
And here is a walkthrough from microsoft http://msdn.microsoft.com/en-us/library/ee340709(v=vs.100).aspx[^] (make sure you have ".NET Framework 4" selected at the top or use "Other versions" dropdown to select it)

I find datagrid/datagridview very convenient for "looking" at database data but it really depends on what you want to do with that data - for example you could convert the data to XML and view it in a webbrowser or, as KM Perumal suggests above, use a ListView control.

The controls that come with VS should be sufficient for your needs - in other words I wouldn't worry about buying / downloading other toolkits just yet. A lot of people use Telerik extensions if you do decide to go down that path, but I've heard you may have some issues with VS2010 Express version - I'm not sure how true that is from personal experience. I would recommend that you try to get as comfortable as possible using the "standard" components first though.
 
Share this answer
 
Comments
Miwin Solutions 12-Apr-13 8:51am    
Hi - thanks for your help
I had found the wpftutorial.net which is some help. The section "Row Details depending on the type of data" is similar to what I want to do - if a cell contains a particular string, I want that row foreground colour to be different. I have struggled with working out how to implement this though!
The other thing that a wish to do is hide column(s) of the DataGrid, but I cant find a way to do this.
I am new to wpf, so looking for simple solutions!
Thanks for your help!
Mike
Miwin Solutions 12-Apr-13 10:44am    
Thanks for the links!
I have tried the foreground colour link, but not got it working yet - sorry for being a beginner at this!
I done this in MainWindow.xaml.cs:

namespace WpfDataGridSQL
{
///
/// Interaction logic for MainWindow.xaml
///

///

[ValueConversion(typeof(DateTime), typeof(String))]
public class NameToBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string input = value as string;
switch (input)
{
case "John":
return Brushes.LightGreen;
default:
return DependencyProperty.UnsetValue;
}
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
...

and then in MainWindow.xaml done this:
<window x:class="WpfDataGridSQL.MainWindow"
="" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="WpfDataGridSQL" title="MainWindow" height="612" width="1057">

<window.resources>
<local:nametobrushconverter x:key="NameToBrushConverter">

...

however I come up with the errors:
Error 1 The tag 'NameToBrushConverter' does not exist in XML...
and
Error 2 The type 'local:NameToBrushConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built....
I have either done something stupid or missing an obvious step!
Thanks for any help...
Mike
Miwin Solutions 12-Apr-13 10:46am    
sorry, in MainWindow.xaml I have done this:
<window x:class="WpfDataGridSQL.MainWindow"
="" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="WpfDataGridSQL" title="MainWindow" height="612" width="1057">

<window.resources>
<local:nametobrushconverter x:key="NameToBrushConverter">

...
Miwin Solutions 12-Apr-13 10:50am    
try this:

xmlns:local="WpfDataGridSQL"
Title="MainWindow" Height="612" Width="1057">

<window.resources>
<local:nametobrushconverter x:key="NameToBrushConverter">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900