views:

100

answers:

3

I'm working on a formsapplication with a datagrid in it. How can I disable or replace (null)-values in cells when im databinding the grid to a database. When I am in the Designer view and clicking on the little arrow on the grid,I only see the option "Autoformat"

A: 

It seems to be that doing a simple boolean check on an object at query time would allow for you to filter nulls. Or in the actual query: not null

http://www.windows-tech.info/15/8234081daef047ee.php

Woot4Moo
No I dont want to eliminate records with null values in some columns, I just want to display it properly in my datagrid. By replacing (null) into "" for example
Janis
well than the other suggestion would be to see if the object that you query back == null or object.myField == null.
Woot4Moo
+1  A: 

You could:

  • To alter your database query to return your null columns with properly values
  • To alter your grid to test if your value is null and deal with it
  • To implement DataGrid.ItemDataBound event and treat your null values there

Depending on your framework version, you could to use null coalescing operator, ?? like:

string test1 = "123" ?? "no value"; // will have "123";
string test2 = null  ?? "no value"; // will have "no value";
Rubens Farias
A: 

Ok, Another question, what grid is the best choise for a windows forms application ? I need to select 1 row at the time and need to edit or delete the row

Janis
janis, SO doesnt work like this; I you have a useful answer, make it as answer, and post another question or you'll not have more answers
Rubens Farias